I can set a width in characters but this is only the “default width” which applies when no file is selected.
To test my layout, I created a file name which is really long and this totally screws up my layout.
If I keep making the window narrower, then at some point the frame, containing my GtkFileChooserButton also gets reduced in width which makes me get the effect, I want to get right away at a defined maximum width of the full frame.
How can I enforce this?
Edit: It actually seems funny that Gtk.FileChooserButton explicitly mentions how to increase the width because the widget will ellipsize the label but I have the exact opposite problem as the widget, for me, will request the width to display the full file name without any way for me to stop this…
I have replaced the “GtkGrid”, I use to organize the widgets, with “GtkTable” (which is deprecated, unfortunately) and this gives me exactly what I need… Is there some way to make GtkGrid behave like GtkTable?
Since you fell back to GtkTable, I have to assume you’re using GTK3.
I would recommend against using GtkFileChooserButton; it was deprecated in GTK4 because it could not be salvaged as a widget, even before the switch to a whole new file selection API that didn’t use widgets.
My recommendation is to use a button that launches a GtkFileChooserNative dialog; you can control the contents of the button, including the label and its ellipsization mode, or its maximum width in characters. Ignore GtkFileChooserButton entirely—which will also make it easier for you to port to GTK4, if you ever decide to do so.
With “control ellipsization mode” you mean that it would be my job to cut the filename at “x characters” and append the three dots, right? I at least could not find any option for a GtkButton to do this automatically.
A GtkButton is a container widget that has some convenience API for setting a label or an image, but you’re free to put whatever you want into it yourself.
If you have specific requirements on the kind of presentation and sizing you want to use, it’s better to use your own widgets.
Thank you. This seems to work but now I get the same problem with GtkComboBoxText elements in the same grid. As the grid column width now dynamically changes when longer text is added to the ComboBox, my length limited button text at some point seems off.
What I really need is some way to FORCE the width of one grid column.
Web developers sometimes say that CSS can be hell, but currently it feels like GTK is worse
In general, there is no way to guarantee that. A parent widget (the GtkTable here) can’t shrink below the minimal width of its child widgets (labels or comboboxes in you case).
As noted by ebassi, the trick is to allow these child widgets to shrink smaller (down to a bottom limit) by using ellipsize properties.
For ComboBoxes it’s possible but a bit tricky: get the cell area with Gtk.CellLayout.get_area, loop over its children, when you see a Gtk.CellRendererText then set its ellipsize property, just like you did for the labels.
Should you port to gtk4, replace the GtkCombobox by GtkDropdown, for which you can use the factory to have full control of the widget displaying the text. A GtkInscription would be a good match here.