In the Ubuntu Accomplishments project we are having a few unusual bugs:

Namely that we have a window with a GtkNotebook and a GtkIconView on a page and another on another page.

When the user re-sizes the window the iconview does not automatically fill the space with icons (they stay in their original column layout) but if the user changes the GtkNotebook pages and thus refreshes the icon view the space is taken up as expected. How can we automatically use the space when resizing the window?

What is more concerning though is that when the window appears, we can resize it smaller - it seems as if the iconview is blocking us from resizing and then having a scrollable region for the icons.

The code looks like this. The ListStores that drive the IconViews:

    self.trophystore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str) # title, icon accomplished, locked, app, accomplishment
    self.trophystore.set_sort_column_id(COL_TITLE, Gtk.SortType.ASCENDING)

    self.oppstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, bool, bool, str, str) # title, icon, accomplished, locked, app, accomplishment
    self.oppstore.set_sort_column_id(COL_TITLE, Gtk.SortType.ASCENDING)



Other than this, we don't really poke around with the IconViews, we just add content to the ListStores to update the views.

The code for the project is here - can anyone recommend how we can fix these two issues?

  • Just an explanation: when the user changes Notebook pages, the application code clears the underlying model and adds all items again, which seems to be the reason for GtkIconView to refresh and use the empty space. Apr 24, 2012 at 11:40

3 Answers 3


Okay, as we have figure out how to fix this, I'll describe the solution here, in case anyone else has this problem.

The trick is to place the GtkIconView in a GtkScrolledWindow, and set it's hscrollbar_policy to "always". Then, a check-resize signal has to be used, to react when the user resizes the window (note that it must be checked if the size has changed, for the signal is emitted also when e.g. the window is dragged around).

When the size changes, the model used by GtkIconView has to be cleared and recreated, as this triggers GtkIconView properly reallocating the newly gained space (or shrinking). Also, as the result the horizontal scrollbar will never be seen, as the GtkIconView uses exactly that much space as the GtkScrolledWindow uses.

  • This has been extremely helpful, thanks for the answer! I was affected by it on lp:qreator and with your fix the number of icon columns in the main icon view is dynamic upon resize again. May 28, 2012 at 6:07

My preferred solution to this problem is a very small subclass of Gtk.IconView:

class FluidIconView (Gtk.IconView):
    def __init__ (self):
        Gtk.IconView.__init__ (self)
        self.connect ("size-allocate", FluidIconView.on_size_allocate)

    def do_get_preferred_width (self):
        return (0,0)

    def on_size_allocate (self, allocation):
        [self.set_columns (m) for m in [1,self.get_columns ()]]

The get_preferred_width override allows the view to be arbitrarily narrow. The size-allocate callback forces a relayout by setting the number of columns to 1 and back.


You can also set the columns to 0 and back to -1 when the size changes. This way the icons won't be deselected:


(This should be done in addition to @rafalcieslak's answer.)

  • Why is this in addition to rafalcieslak's answer? If you change the number of columns, you'll get a relayout; rebuilding the model anyway would be pointless.
    – cscarney
    Aug 20, 2012 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .