Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML: custom ComboBox, close behaviour/focus

QML: custom ComboBox, close behaviour/focus

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glinbob
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      drgvond
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved