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. Beispiel

_images/iconview_example.png
 1import gi
 2
 3gi.require_version("Gtk", "3.0")
 4from gi.repository import Gtk
 5from gi.repository.GdkPixbuf import Pixbuf
 6
 7icons = ["edit-cut", "edit-paste", "edit-copy"]
 8
 9
10class IconViewWindow(Gtk.Window):
11    def __init__(self):
12        Gtk.Window.__init__(self)
13        self.set_default_size(200, 200)
14
15        liststore = Gtk.ListStore(Pixbuf, str)
16        iconview = Gtk.IconView.new()
17        iconview.set_model(liststore)
18        iconview.set_pixbuf_column(0)
19        iconview.set_text_column(1)
20
21        for icon in icons:
22            pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0)
23            liststore.append([pixbuf, "Label"])
24
25        self.add(iconview)
26
27
28win = IconViewWindow()
29win.connect("destroy", Gtk.main_quit)
30win.show_all()
31Gtk.main()