QML: custom ComboBox, close behaviour/focus



  • Hello everyone,

    i'm currently working on a custom combo box control in pure qml (yes, i know there is qtuick controls...), works fine so far, aside from one tiny issue: In virtually any UI-Toolkit Library, a combo box closes as soon as you click anywhere outside the (open) combo box. I can't get that working for me, at least not in an elegant way :(.

    What /should/ work is setting up some fake (invisible) mouse area, which intercepts all clicks and grabs the focus, while the comboBox reacts to onFocusChanged/onActiveFocusChanged or similar and closes its popup. Or i could intercept mouse clicks on the cpp level (basically the same but on a different stage). Anyway, all those solutions look like some dirty workarounds to me :|
    Maybe i haven't read the docs good enough, shouldn't there be some general inbuilt mechanism to lose the focus as soon as the user clicks somewhere else? As this is typical common behaviour to almost any control?

    TiA
    Glinbob



  • Hi,

    What you need is mouse grabbing and checking whether the user has clicked inside or outside the window. AFAIK, the API needed to implement is not available in QML. (Having a screen-wide window is a "no go" for obvious performance and memory reasons)

    I implemented both combo box and menus for Qt Quick Controls, and the core of the interaction is in the QQuickMenuPopupWindow class (https://qt.gitorious.org/qt/qtquickcontrols/source/0bf5b80baee78f9fc7145304821481556ccba78b:src/controls/qquickmenupopupwindow_p.h). This class also works for menus, meaning it tracks things like moving the mouse cursor on the parent menu window, and such.

    Hope it helps you find some inspiration.

    Cheers,

    Gabriel


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.