16. IconView¶
A Gtk.IconView
is a widget that displays a collection of icons in a grid view. It supports features such as drag and drop, multiple selections and item reordering.
Similarly to Gtk.TreeView
, Gtk.IconView
uses a Gtk.ListStore
for its model. Instead of using cell renderers, Gtk.IconView
requires that one of the columns in its Gtk.ListStore
contains GdkPixbuf.Pixbuf
objects.
Gtk.IconView
supports numerous selection modes to allow for either selecting multiple icons at a time, restricting selections to just one item or disallowing selecting items completely. To specify a selection mode, the Gtk.IconView.set_selection_mode()
method is used with one of the Gtk.SelectionMode
selection modes.
16.1. Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk from gi.repository.GdkPixbuf import Pixbuf icons = ["edit-cut", "edit-paste", "edit-copy"] class IconViewWindow(Gtk.Window): def __init__(self): super().__init__() self.set_default_size(200, 200) liststore = Gtk.ListStore(Pixbuf, str) iconview = Gtk.IconView.new() iconview.set_model(liststore) iconview.set_pixbuf_column(0) iconview.set_text_column(1) for icon in icons: pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0) liststore.append([pixbuf, "Label"]) self.add(iconview) win = IconViewWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main() |