Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox
Forum Updated to NodeBB v4.3 + New Features

QComboBox

Scheduled Pinned Locked Moved Solved General and Desktop
qcombobox
8 Posts 2 Posters 346 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.
  • J Offline
    J Offline
    Jiej
    wrote last edited by
    #1

    Hi,

    I am using a QComboBox and when the current index is -1 and it's editable, the popup / dropdown works normally : when I open it, it remains open until an item is selected or it loses focus. But when an item is selected (index ≠ -1) and the combo is not editable, the popup / dropdown remains open only if I hold the mouse button.

    Does anybody know how to change that ?

    jsulmJ 1 Reply Last reply
    0
    • J Offline
      J Offline
      Jiej
      wrote last edited by
      #8

      I've fixed it by reimplementing QComboBox::showPopup() by setting the index to -1 before actually showing the popup because when the current index is -1, the popup displays well.

      1 Reply Last reply
      0
      • J Jiej

        Hi,

        I am using a QComboBox and when the current index is -1 and it's editable, the popup / dropdown works normally : when I open it, it remains open until an item is selected or it loses focus. But when an item is selected (index ≠ -1) and the combo is not editable, the popup / dropdown remains open only if I hold the mouse button.

        Does anybody know how to change that ?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote last edited by
        #2

        @Jiej Not sure I understand: you want to click on an entry inside QComboBox without it closing? What is the use case?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jiej
          wrote last edited by Jiej
          #3

          @jsulm
          I want the popup to close only after an item is selected (clicked).
          Currently, when the index ≠ -1 and I open the popup, it closes when I release the mouse button (and haven't selected an item yet)

          jsulmJ 1 Reply Last reply
          0
          • J Jiej

            @jsulm
            I want the popup to close only after an item is selected (clicked).
            Currently, when the index ≠ -1 and I open the popup, it closes when I release the mouse button (and haven't selected an item yet)

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote last edited by
            #4

            @Jiej said in QComboBox:

            Currently, when the index ≠ -1 and I open the popup, it closes when I release the mouse button (and haven't selected an item yet)

            That should not happen. Do you do anything special with this combo box? What is the platform and Qt version?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Jiej said in QComboBox:

              Currently, when the index ≠ -1 and I open the popup, it closes when I release the mouse button (and haven't selected an item yet)

              That should not happen. Do you do anything special with this combo box? What is the platform and Qt version?

              J Offline
              J Offline
              Jiej
              wrote last edited by Jiej
              #5

              @jsulm I use Qt 6 on Ubuntu / Linux.
              There are a lot of items in my combo and I use it via subclassing. I also modified its original behavior by connecting its signal currentIndexChanged to a slot that sets the index to -1 if the currentIndex is 0.

              jsulmJ 1 Reply Last reply
              0
              • J Jiej

                @jsulm I use Qt 6 on Ubuntu / Linux.
                There are a lot of items in my combo and I use it via subclassing. I also modified its original behavior by connecting its signal currentIndexChanged to a slot that sets the index to -1 if the currentIndex is 0.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote last edited by
                #6

                @Jiej said in QComboBox:

                currentIndexChanged to a slot that sets the index to -1 if the currentIndex is 0

                That could be the reason. Try without this: does it work?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @Jiej said in QComboBox:

                  currentIndexChanged to a slot that sets the index to -1 if the currentIndex is 0

                  That could be the reason. Try without this: does it work?

                  J Offline
                  J Offline
                  Jiej
                  wrote last edited by Jiej
                  #7

                  @jsulm
                  I think I understood what's happening.
                  As I said, my QComboBox has a lot of items and because of this, the popup position is shifted when I click on the field to open it and the mouse cursor falls within the area of the popup and when I release the mouse button, Qt thinks I selected an item and closes the popup.

                  3feb6e5a-095d-4b3c-abbf-c0273e361076-Screenshot from 2025-09-18 19-24-08.png
                  7889ae48-11a3-4a8f-999c-03c86fbee7e4-image.png

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jiej
                    wrote last edited by
                    #8

                    I've fixed it by reimplementing QComboBox::showPopup() by setting the index to -1 before actually showing the popup because when the current index is -1, the popup displays well.

                    1 Reply Last reply
                    0
                    • J Jiej has marked this topic as solved

                    • Login

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