Mouse over/hover highlighting of combo list items
-
With the default
ComboBox, the currently selected item is highlighted when the popup list is shown. I would like to implement in addition some visual feedback when the mouse passes over each item of the open popup list as is common for selectable items in many GUIs. In particular it would highlight the item you are about to select. This would be similar to the current selected item highlighting but be a different colour.I don't think there is a way to do this without customising the
popupat least. Even then it is not clear. I did try following the customisation guide from the docs for this, and added my ownpopupbased onListView, but I could not see a way to implement the hover behaviour without aMouseAreaover theListView. The problem then is that theMouseAreaseems to interfere with the normal behaviour of theComboBox.Am I missing anything straightforward here or am I on the right lines with the approach I outlined?
-
With the default
ComboBox, the currently selected item is highlighted when the popup list is shown. I would like to implement in addition some visual feedback when the mouse passes over each item of the open popup list as is common for selectable items in many GUIs. In particular it would highlight the item you are about to select. This would be similar to the current selected item highlighting but be a different colour.I don't think there is a way to do this without customising the
popupat least. Even then it is not clear. I did try following the customisation guide from the docs for this, and added my ownpopupbased onListView, but I could not see a way to implement the hover behaviour without aMouseAreaover theListView. The problem then is that theMouseAreaseems to interfere with the normal behaviour of theComboBox.Am I missing anything straightforward here or am I on the right lines with the approach I outlined?
OK, so I think it is more straightforward.
I was thinking that I had to customise both the
popupand thedelegate. Thedelegatedefines the items shown in the popup list.However, what I had missed was, that the
delegateis defined (as demonstrated in the customisation docs) using anItemDelegate. This is essentially a buttonControland therefore supports hovering out of the box. So it was as simple as adding the following and not needing a custompopup:ComboBox { ... delegate: ItemDelegate { ... hoverEnabled: true // <<<< contextItem: Text { ... } background: Rectangle { anchors.fill: parent color: { // Use `hovered` in logic for background colour index === control.currentIndex ? "blue" : (hovered ? "yellow" : "white") } ... } ... } -
B Bob64 has marked this topic as solved on