Ellipsize on a text column in a gtk iconview

How do I get ellipsize working? This is my code:

GtkCellRenderer *cell = gtk_cell_renderer_text_new();
	gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(media_iconview), cell, TRUE );
	gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(media_iconview), cell,  "ellipsize", PANGO_ELLIPSIZE_END, NULL);
	g_object_set(cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
	gtk_icon_view_set_text_column(GTK_ICON_VIEW (media_iconview),1);

ellipsize

Sadly all the examples on Google are related to GtkTreeview.

Hi,

The text will start ellipsize only once the widget reaches its maximum size.
So you probably need to add some kind of limitation somewhere.

For a CellRendererText, thatā€™s probably be the max-width-chars property.

gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(media_iconview), cell, ā€œmax-width-charsā€, -1, NULL);

Thank you so much for replying. After adding that line I get:

(imagination:48756): Gtk-CRITICAL **: 14:49:49.358: gtk_cell_layout_add_attribute: assertion ā€˜column >= 0ā€™ failed

And still no ellipsize. Do you have any other idea?

I expect more something like:

g_object_set(cell, "max-width-chars", 20, NULL);

I added this line, no messages in the console but the text is still not ellipsized. :sob: :sob: am I missing some specific setting to gtk_iconview? Do you know any software which uses iconview with a text column? I tried to look inside Nemo file manager sources but with no luck.

I do appreciate your help.

Hm, Iā€™m a bit confusedā€¦

Why do you create a new CellRendererText and at the same time use the existing one with gtk_icon_view_set_text_column?

If you use gtk_icon_view_set_text_column, then get the existing renderer with Gtk.CellLayout.get_cells and apply the ellipsize and max-width-chars
to it.

Otherwise, is you use your own renderer, donā€™t call gtk_icon_view_set_text_column but instead use gtk_cell_layout_set_attributes to link the text to the appropriate modelā€™s column.

GtkCellRenderer *cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_end( GTK_CELL_LAYOUT(media_iconview), cell, TRUE );
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(media_iconview), cell,  "text", 1, NULL);
g_object_set(cell, "ellipsize", PANGO_ELLIPSIZE_END, "max-width-chars", 20, NULL);
1 Like

If it still doesnā€™t work, you can add a new column to your model and use it to store a manually ellipsized string.

Then pass this column index to gtk_icon_view_set_text_column, so the iconview can use it.

1 Like

Your code worked like a charm! You are a genious! Thank you for the patience and the kind explanation, I learnt something new about cell renderers. Would you like to help in your spare time to the development of my slideshow maker? I have been developing it since 2009. If you want to give a look itā€™s here: https://github.com/colossus73/imagination

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.