GTK ComboBox, DropDown (etc.?) no longer pre-select active item on popup

In GTK3, GtkComboBox (and GtkMenu, et al.) would open the popup and have the item/button therein pre-selected, for the current index. For instance, in a country selector, if USA was selected and shown on the button, when clicking to open the popup, it’d get focus in the menu.

This no longer happens in GTK4. Instead, the first/top item gets initial focus every time, regardless of it not being the active option. That’s jarring and inconvenient, as well as a regression from GTK3 and when compared to other toolkits, where I think GTK3’s behaviour is the norm.

Was this intentionally omitted? If not, would a patch to fix be reviewed? In my own popup widget I just do something like Popover::show -> ::idle -> activeButton.grab_focus(), and it seems to work OK so far…

1 Like

I see the same with gtk4 4.10.3 but I’m unsure this is a problem. The combobox/dropdown displays the selected choice also when the popup is open. For example below “Middle” is the selected choice and it shows that even if the highlighted choice is now “Left”:

image

Closing the popup without selecting another choice (by pressing Esc or clicking outside the popup) doesn’t change the selected choice.

And as soon as you start moving your mouse over the popup the highlight is changed to the moved over choice.

I know all of that. My point is not that the ‘real’ current item gets changed when it shouldn’t (it doesn’t) - but that it’s not got the initial focus in the popup anymore, when it did in GTK3. This is misleading, and disruptive if you’re used, as I am, to being able to open a combobox/menu/whatever with keyboard, see focus on the current active item, and move from there to the item I want to choose. Now I can’t do that, and must start from the top item each time, despite it not being the active one. This seems like an unnecessary loss in usability, and so I hope it can be fixed.

1 Like

Can anyone from the GTK team comment, please?

GtkDropDown uses GtkListView to show the list of items; focus of GtkListView rows is being addressed by the sections merge request, which adds the ability to focus list items. For GTK 4.12, we could make GtkDropDown focus the active item when the popup is open.

1 Like

Great, thanks! Then while I can’t currently give an ETA, I’ll try to submit an MR for that, unless someone beats me to it.

Could we consider doing the same for ComboBox at the same time? Just for consistency and to plug that gap vs. GTK3.

Nothing should have changed for GtkComboBox: the code should be the same in GTK3 and GTK4. More investigation would be required.

It has changed quite a bit: whereas in GTK3 ComboBox used a Menu (let’s not dare to mention appears-as-list mode), in GTK4 Menu is gone so it uses a Popover which Inspector shows is a GtkTreePopover. I haven’t looked further but imagine that the auto-focussing of the active item was lost or broke in that rewrite.

Edit: The code that would have ‘pre-selected’ (in this case, moved to the cursor) the active item has been disabled with a big #if 0. Also, the entire widget is in deprecated/. Well, I’ll aim to include an equivalent patch anyway, alongside the DropDown one.

For GTK 4.12, we could make GtkDropDown focus the active item when the popup is open.

I’m not sure it’ll be that easy? The GtkListView does not provide any way to get the widget that’s currently showing a given model item, and is clear about this being because that widget could be recycled for another model item.

focus of GtkListView rows is being addressed by the sections merge request

Was it? That’s merged; I don’t see anything about focus in the commit messages, only a checklist item in one of @otte 's comments, which remains unticked; and in current main I don’t see any reference to setting a specific focus, only moving it around… so it’s not clear to me if this changes anything.

Moving to a GitLab Issue: link

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