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. No way to handle comboBox popup visibility
Forum Updated to NodeBB v4.3 + New Features

No way to handle comboBox popup visibility

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.5k 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.
  • N Offline
    N Offline
    Nicola Peroni
    wrote on last edited by Nicola Peroni
    #1

    Hi all,

    I would like to check the visibility of a QtQuick.Controls2 ComboBox popup but there doesn't seem to be any way to do this.

    I would like the popup to remain visible as long as ComboBox has the activeFocus.
    I tried starting from qt official guide - customizing combobox and by changing the popup closePolicy property to Popup.NoAutoClose, but it does not change anything and popup keeps closing when clicking outside!

    Here is a little example

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.3
    
    Window {
        visible: true
        width: 640
        height: 480
    
        ComboBox {
            id: control
    
            editable: true
            indicator: null
    
            model: ListModel {
                id: model
    
                ListElement { text: "Banana" }
                ListElement { text: "Apple" }
                ListElement { text: "Coconut" }
            }
    
            onActiveFocusChanged: {
                console.log("onActiveFocusChanged", activeFocus)
                if (activeFocus)
                    popup.open()
                else
                    popup.close() // Note: this is not called when clicking outside the ComboBox
            }
    
            popup: Popup {
                y: control.height - 1
                width: control.width
                implicitHeight: contentItem.implicitHeight
                padding: 1
                closePolicy: Popup.NoAutoClose // <---------- completely ignored!
                // visible: control.activeFocus // This should be a declarative way to be used instead of onActiveFocusChanged callback, but doesn't works!
                onVisibleChanged: console.log("visible changed to", visible, ", control activeFocus is", control.activeFocus) // log just to highlight the issue
                contentItem: ListView {
                    clip: true
                    implicitHeight: contentHeight
                    model: control.popup.visible ? control.delegateModel : null
                    currentIndex: control.highlightedIndex
                    ScrollIndicator.vertical: ScrollIndicator { }
                }
    
                background: Rectangle {
                    border.color: "#21be2b"
                    radius: 2
                }
            }
        }
    }
    

    This is the application output:

    when I click on the ComboBox:

    qml: onActiveFocusChanged true
    qml: visible changed to true , control activeFocus is true
    

    when I click outside the Popup:

    qml: visible changed to false , control activeFocus is true
    

    Is this a bug or am I doing something wrong?
    Thanks in advance

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      I played around with it a lot. It feels kind of like a bug to me. It acted weird, like if it disappeared but I moved the window it would reappear. If I clicked outside the window it was fine but if I clicked the window background (i.e. outside the popup but inside the application) it would hide.

      Seems like a bug, but I admit I'm not good with QML so maybe someone else can explain why that is happening. I would file a bug if you don't get an answer.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      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