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. Strange behavior on ComboBox when playing with focus and popup.visible
QtWS25 Last Chance

Strange behavior on ComboBox when playing with focus and popup.visible

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 2.6k Views
  • 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.
  • F Offline
    F Offline
    Fheanor
    wrote on last edited by Fheanor
    #1

    Hello,

    I have a strange behavior that is annoying me when I try to do this code:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
       
    ApplicationWindow {
        id: window
        visible: true
        width: 640
        height: 480
        
        Rectangle {
            color: "green"
            width: parent.width/2
            height: parent.height
            anchors.right : parent.right
    
            ComboBox {
                id:combo
                popup.visible: combo.activeFocus
                model: [ "Banana", "Apple", "Coconut" ]
            }      
        }
        CheckBox {
            id:check
        }
    }
    

    If I click on the CheckBox and then on the ComboBox , the ComboBox.popup will appears during 1 ms and then disapears.
    I don't understand why because activeFocus = true

    Do you have any idea why ?

    E 1 Reply Last reply
    0
    • F Fheanor

      Hello,

      I have a strange behavior that is annoying me when I try to do this code:

      import QtQuick 2.7
      import QtQuick.Controls 2.0
         
      ApplicationWindow {
          id: window
          visible: true
          width: 640
          height: 480
          
          Rectangle {
              color: "green"
              width: parent.width/2
              height: parent.height
              anchors.right : parent.right
      
              ComboBox {
                  id:combo
                  popup.visible: combo.activeFocus
                  model: [ "Banana", "Apple", "Coconut" ]
              }      
          }
          CheckBox {
              id:check
          }
      }
      

      If I click on the CheckBox and then on the ComboBox , the ComboBox.popup will appears during 1 ms and then disapears.
      I don't understand why because activeFocus = true

      Do you have any idea why ?

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @Fheanor Why are you doing it that way in the first place? If you comment out the popup.visible line it behaves as it should.

      At first I thought it first takes the visibility from the mouse area click, then handles the click by itself. Because it's already open when it handles the click it is closed, as it should when it is clicked while it's already open.

      But then I tested. It's more probable that the combobox handles the click ( if you add console.log to MouseArea onClicked it doesn't print), gets active focus, opens the popup which then gets the active focus, combobox looses the active focus and the popup goes not visible.

      F 1 Reply Last reply
      0
      • E Eeli K

        @Fheanor Why are you doing it that way in the first place? If you comment out the popup.visible line it behaves as it should.

        At first I thought it first takes the visibility from the mouse area click, then handles the click by itself. Because it's already open when it handles the click it is closed, as it should when it is clicked while it's already open.

        But then I tested. It's more probable that the combobox handles the click ( if you add console.log to MouseArea onClicked it doesn't print), gets active focus, opens the popup which then gets the active focus, combobox looses the active focus and the popup goes not visible.

        F Offline
        F Offline
        Fheanor
        wrote on last edited by
        #3

        @Eeli-K I don't think it is what you said because if you click on the ComboBox without clicking on the CheckBox, it will works fine. If what you said is true, we should expect same behavior.

        I need to be able to open the popup while clicking on something else than the ComboBox. The MouseArea here is just an example, it could be another Item

        E 2 Replies Last reply
        0
        • F Fheanor

          @Eeli-K I don't think it is what you said because if you click on the ComboBox without clicking on the CheckBox, it will works fine. If what you said is true, we should expect same behavior.

          I need to be able to open the popup while clicking on something else than the ComboBox. The MouseArea here is just an example, it could be another Item

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @Fheanor If you try

          ComboBox {
                      id:combo
                      popup.visible: combo.activeFocus
                      model: [ "Banana", "Apple", "Coconut" ]
                      onCurrentIndexChanged: {
                          console.log("new text", combo.currentText)
                          check.forceActiveFocus()
                      }
                  }
          

          You see that moving the active focus creates the problem somehow.

          F 1 Reply Last reply
          0
          • E Eeli K

            @Fheanor If you try

            ComboBox {
                        id:combo
                        popup.visible: combo.activeFocus
                        model: [ "Banana", "Apple", "Coconut" ]
                        onCurrentIndexChanged: {
                            console.log("new text", combo.currentText)
                            check.forceActiveFocus()
                        }
                    }
            

            You see that moving the active focus creates the problem somehow.

            F Offline
            F Offline
            Fheanor
            wrote on last edited by Fheanor
            #5

            @Eeli-K It is not just about that, I edited my code to make it more simple. And the problem still occur

            I tried this but it doesn't work:

            popup.visible: combo.focus || combo.popup.focus
            
            1 Reply Last reply
            0
            • F Fheanor

              @Eeli-K I don't think it is what you said because if you click on the ComboBox without clicking on the CheckBox, it will works fine. If what you said is true, we should expect same behavior.

              I need to be able to open the popup while clicking on something else than the ComboBox. The MouseArea here is just an example, it could be another Item

              E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #6

              @Fheanor said in Strange behavior on ComboBox when playing with focus and popup.visible:

              I need to be able to open the popup while clicking on something else than the ComboBox. The MouseArea here is just an example, it could be another Item

              In that case, how about this:

              ComboBox {
                      anchors.top: parent.top
                      id:combo
                      model: [ "Banana", "Apple", "Coconut" ]
                  }
                  CheckBox {
                      anchors.bottom: parent.bottom
                      onCheckedChanged: {
                          if (checked) {
                              combo.popup.open()
                          }
                      }
                  }
              
              F 1 Reply Last reply
              0
              • E Eeli K

                @Fheanor said in Strange behavior on ComboBox when playing with focus and popup.visible:

                I need to be able to open the popup while clicking on something else than the ComboBox. The MouseArea here is just an example, it could be another Item

                In that case, how about this:

                ComboBox {
                        anchors.top: parent.top
                        id:combo
                        model: [ "Banana", "Apple", "Coconut" ]
                    }
                    CheckBox {
                        anchors.bottom: parent.bottom
                        onCheckedChanged: {
                            if (checked) {
                                combo.popup.open()
                            }
                        }
                    }
                
                F Offline
                F Offline
                Fheanor
                wrote on last edited by
                #7

                @Eeli-K Sorry for the late answer, I was not at work.
                Your solution is what I need, when I play with popup.open() and not popup.visible: combo.activeFocus , it works.
                Thanks a lot !

                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