I use the code above to create toolbar and button with gtk+3.24. The button, with single character label ‘^’, looks too wide for me. How can i make it narrow? specify width in pixel? or anything to do with margin or padding?
thanks! I had tried some CSS snippet and c code found on web before but not work, so i ask the question here. The CSS snippet i had found was different.
I just realized that i should open my gtk application with GTK_DEBUG=interactive to view the css
I would report for any difficulty applying this new css. Thanks in advance!
UPDATE: after i change GTK_ALIGN_FILL to GTK_ALIGN_START, the left most toolbar button become narrower. However, there is still a big gap between the first button and the second one, why?
I would guess this comes from how the space for the widgets are allocated. Normally, widgets will use all the space allocated to them, if you’re not using halign or valign. When you set halign to start, the widget only uses the width it needs, but the rest of it is still allocated of this widget and can’t be used by another one.
I’m don’t know how exactly Gtk.Toolbar does allocate its widgets. However, based on your issue, I would assume it allocates the same width to each widget. Since your other widgets are wider, it gives them more space, but also the first one.
I would say the solution is to switch to using a Gtk.Box instead, as there the widgets can have variable width.
Thanks for replying, i would find some snippet of Gtk.Box and try.
Currently, i am using gtk_toolbar_insert to add buttons into toolbar. This function has a position parameter. I use value -1 for this parameter which means append the new button at the end. Except for the second button, the one with label ‘/home/guyuming/…’ on the screenshot. I set the position value to some positive number. However, it does not seem to have any effect regardless what the positive number is, 40, 60, 300. The second button always start at the same position as the screenshot shows.
Well, the position parameter here is for the position in the list of items, not an absolute position on the screen.
So, setting it to, say 5, says “insert this item after the fifth item in the toolbar”. Where the position of that fifth item is is up to what widgets are added and their size requests.