IconView


Object Hierarchy:

Gtk.IconView Gtk.IconView Gtk.IconView Gtk.Container Gtk.Container Gtk.Container->Gtk.IconView Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.IconView Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.IconView Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget Gtk.CellLayout Gtk.CellLayout Gtk.CellLayout->Gtk.IconView Gtk.Scrollable Gtk.Scrollable Gtk.Scrollable->Gtk.IconView

Description:

[ CCode ( type_id = "gtk_icon_view_get_type ()" ) ]
public class IconView : Container, Implementor, Buildable, CellLayout, Scrollable

IconView provides an alternative view on a TreeModel.

It displays the model as a grid of icons with labels. Like TreeView, it allows to select one or multiple items (depending on the selection mode, see set_selection_mode). In addition to selection with the arrow keys, IconView supports rubberband selection, which is controlled by dragging the pointer.

Note that if the tree model is backed by an actual tree store (as opposed to a flat list where the mapping to icons is obvious), IconView will only display the first level of the tree and ignore the tree’s branches.

CSS nodes

iconview.view
╰── [rubberband]
conView has a single CSS node with name iconview and style class .view. For rubberband selection, a subnode with name rubberband is used.

Example: IconView:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.IconView";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (400, 400);

// The Model:
Gtk.ListStore model = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
Gtk.TreeIter iter;

// The IconView:
Gtk.IconView view = new Gtk.IconView.with_model (model);
view.set_pixbuf_column (0);
view.set_text_column (1);
this.add (view);

// Data:
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();

try {
model.append (out iter);
Gdk.Pixbuf pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Dialog");

model.append (out iter);
pixbuf = icon_theme.load_icon ("document-print", 20, 0);
model.set (iter, 0, pixbuf, 1, "Print");

model.append (out iter);
pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Help");
} catch (Error e) {
// TODO
assert_not_reached ();
}


view.selection_changed.connect (() => {
List<Gtk.TreePath> paths = view.get_selected_items ();
Value title;
Value icon;

foreach (Gtk.TreePath path in paths) {
bool tmp = model.get_iter (out iter, path);
assert (tmp == true);

model.get_value (iter, 0, out icon);
model.get_value (iter, 1, out title);
print ("%s: %p\n", (string) title, ((Gdk.Pixbuf) icon));
}
});
}

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.IconView.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor