GNOME Bugzilla – Bug 662043
gtk_widget_set_size_request no longer works with GtkLabel
Last modified: 2012-01-03 06:26:49 UTC
Created attachment 199279 [details] Test program In GTK+ 2.x, you can use gtk_label_set_ellipsize() and then gtk_widget_set_size_request() to make a GtkLabel fit within a certain width. In GTK+ 3.x, this no longer works. Running Arch Linux x86_64 with gtk2 2.24.6-2 and gtk3 3.2.0-2. I am attaching a simple test program. Please look at the screenshots of the same program compiled with GTK+ 2.x and with GTK+ 3.x and note the difference.
Created attachment 199280 [details] Screenshot with GTK+ 2.x
Created attachment 199281 [details] Screenshot with GTK+ 3.x
I'm affected by this bug too. In my (simplified)case: I have a label inside a non-resizable window and after some events the label changes his text. If label's new size is greater than window size the window is resized to a wider one, breaking UI desing (label has ellipsize property on). Any developer can throw some ideas here?
Hi, this can be closed, as apparently using gtk_widget_set_size_request() to set the width of a label is deprecated in GTK+ 3, and the new way is to use gtk_label_set_width_chars() and gtk_label_set_max_width_chars(). For more info, see this mail and the preceding thread: http://mail.gnome.org/archives/gtk-app-devel-list/2011-December/msg00023.html
(In reply to comment #3) > I'm affected by this bug too. > > In my (simplified)case: I have a label inside a non-resizable window and after > some events the label changes his text. > > If label's new size is greater than window size the window is resized to a > wider one, breaking UI desing (label has ellipsize property on). > > Any developer can throw some ideas here? Ok, this came up before... gtk_widget_set_size_request() sets the "minimum possible size" of a widget... any calls to this api will ensure that a widget is *at least* as big as the request which was set. In GTK+2, there was some code (IMO: ugly hack) where GtkLabel peeks at the explicitly set minimum size request and actually limited the GtkLabel's size for that case. Note that GtkLabel was the only culprit of handling the user set minimum request explicitly and this has been removed in GTK+3. What you need to be using is "width-chars" and "max-width-chars" conjunction with either ellipsize mode or wrap mode. width-chars: Will have essentially the same effect as gtk_widget_set_size_request(), it will request enough space for 'n charachters' and uses an approximation which should show around the same amount of characters with any font resolution. max-width-chars: Will limit the natural size request of the label to the width required by the said number of characters. Note that in GTK+3 there is a difference between 'minimum size' and 'natural size' definition, 'max-width-chars' limits the possible natural size request while 'width-chars' forces a 'minimum size'. A GtkWindow in GTK+-3, like GTK+-2, will constrain the window size to the minimum request of it's contents (the window cannot be shrunk but the user to a size less than the "minimum height for minimum width"). Unlike GTK+-2, a default size will be guessed automatically, the default size of the window will be guessed as the "natural height for natural width". If the window is not user-resizable, then some oddities apply, non-resizable windows "shrink" automatically (I believe to the "minimum height for minimum width", however that might now be the "natural height for natural width"). Hope this helps to clarify things for your application.