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. [SOLVED]How to get/override click event of ComboBox ?

[SOLVED]How to get/override click event of ComboBox ?

Scheduled Pinned Locked Moved QML and Qt Quick
combobox
7 Posts 2 Posters 4.5k 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.
  • B Offline
    B Offline
    beidaochuan
    wrote on 29 Aug 2015, 07:59 last edited by beidaochuan 9 Feb 2015, 23:22
    #1

    How to get/override click event (not currentIndexChanged) of ComboBox ?

    P 1 Reply Last reply 29 Aug 2015, 15:53
    0
    • B beidaochuan
      29 Aug 2015, 07:59

      How to get/override click event (not currentIndexChanged) of ComboBox ?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 29 Aug 2015, 15:53 last edited by
      #2

      @beidaochuan What is your usecase ? I guess the only way would be to create you own custom Combo box and using MouseArea for handling those events.

      157

      B 1 Reply Last reply 30 Aug 2015, 23:50
      0
      • P p3c0
        29 Aug 2015, 15:53

        @beidaochuan What is your usecase ? I guess the only way would be to create you own custom Combo box and using MouseArea for handling those events.

        B Offline
        B Offline
        beidaochuan
        wrote on 30 Aug 2015, 23:50 last edited by
        #3

        @p3c0 I want to turn a buzzer on when clicking ComboBox. So I studied the original codes of ComboBox and found that MouseArea and onClickedas follows.

        MouseArea {
                id: mouseArea
                property bool overridePressed: false
                readonly property bool effectivePressed: (pressed || overridePressed) && containsMouse
                anchors.fill: parent
                hoverEnabled: true
                onPressed: {
                    if (comboBox.activeFocusOnPress)
                        forceActiveFocus()
                    if (!Settings.hasTouchScreen)
                        popup.toggleShow()
                    else
                        overridePressed = true
                }
                onCanceled: overridePressed = false
                onClicked: {
                    if (Settings.hasTouchScreen)
                        popup.toggleShow()
                    overridePressed = false
                }
                onWheel: {
                    if (wheel.angleDelta.y > 0) {
                        __selectPrevItem();
                    } else if (wheel.angleDelta.y < 0){
                        __selectNextItem();
                    }
                }
            }
        

        I guess I need to override the click event, am I right ? But I have no idea how to do it...

        P 1 Reply Last reply 31 Aug 2015, 05:03
        0
        • B beidaochuan
          30 Aug 2015, 23:50

          @p3c0 I want to turn a buzzer on when clicking ComboBox. So I studied the original codes of ComboBox and found that MouseArea and onClickedas follows.

          MouseArea {
                  id: mouseArea
                  property bool overridePressed: false
                  readonly property bool effectivePressed: (pressed || overridePressed) && containsMouse
                  anchors.fill: parent
                  hoverEnabled: true
                  onPressed: {
                      if (comboBox.activeFocusOnPress)
                          forceActiveFocus()
                      if (!Settings.hasTouchScreen)
                          popup.toggleShow()
                      else
                          overridePressed = true
                  }
                  onCanceled: overridePressed = false
                  onClicked: {
                      if (Settings.hasTouchScreen)
                          popup.toggleShow()
                      overridePressed = false
                  }
                  onWheel: {
                      if (wheel.angleDelta.y > 0) {
                          __selectPrevItem();
                      } else if (wheel.angleDelta.y < 0){
                          __selectNextItem();
                      }
                  }
              }
          

          I guess I need to override the click event, am I right ? But I have no idea how to do it...

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 31 Aug 2015, 05:03 last edited by
          #4

          @beidaochuan Do you mean clicking on the box and not on the dropdown items ?

          157

          B 1 Reply Last reply 1 Sept 2015, 00:22
          0
          • P p3c0
            31 Aug 2015, 05:03

            @beidaochuan Do you mean clicking on the box and not on the dropdown items ?

            B Offline
            B Offline
            beidaochuan
            wrote on 1 Sept 2015, 00:22 last edited by
            #5

            @p3c0 yes. I want to turn a buzzer when clicking on the box.

            P 1 Reply Last reply 1 Sept 2015, 09:02
            0
            • B beidaochuan
              1 Sept 2015, 00:22

              @p3c0 yes. I want to turn a buzzer when clicking on the box.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 1 Sept 2015, 09:02 last edited by
              #6

              @beidaochuan Well then following should work:

              ComboBox {
                  width: 200
                  model: [ "Banana", "Apple", "Coconut" ]
                  onPressedChanged: if (pressed) { console.log("Clicked") }
              }
              

              157

              B 1 Reply Last reply 1 Sept 2015, 09:19
              0
              • P p3c0
                1 Sept 2015, 09:02

                @beidaochuan Well then following should work:

                ComboBox {
                    width: 200
                    model: [ "Banana", "Apple", "Coconut" ]
                    onPressedChanged: if (pressed) { console.log("Clicked") }
                }
                
                B Offline
                B Offline
                beidaochuan
                wrote on 1 Sept 2015, 09:19 last edited by
                #7

                @p3c0 Thank, it works well.

                1 Reply Last reply
                0

                3/7

                30 Aug 2015, 23:50

                • Login

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