HowTo: Gtk.IconView with One Row

Ever wondered how you can achieve a layout like below with GTK? Well you can, it is slightly hacky, but very quick to implement – which suits me 🙂

The layout we are trying to achieve

Unfortunately Gtk.IconView doesn’t have a set_rows() function, but it does have a  set_columns() function, which we can use.

All you have to do is call the set_columns() function on the Gtk.IconView and change the default value of -1 (i.e. vary the number of columns based on the width it is given) to a high number, I use 999.


Now the IconView will fill up until that number of columns, and then start a new row, however if the number is high enough, it will never reach it and therefore never start a new row!

If you wanted to do something less hacky and more clever, you could find out the number of items that will be in the IconView, and then set the number of columns to that number to achieve the same effect.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: