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. How to size QComboBox popup height to the count of items

How to size QComboBox popup height to the count of items

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 6.0k Views 2 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    Re: Dynamically fit QComboBox popup height to the (dynamically changing) count of items

    is there no definitive answer to this? my "dropdown" always has a scroll bar when it doesn't need to:

    0_1564598569571_Screen Shot 2019-07-31 at 11.42.35 AM.png

    How do i tell it to resize just enough such that there's no scroll bar?

    jsulmJ 1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #7

      @vmanso said in How to size QComboBox popup height to the count of items:

      maxVisibleItems

      that was it! thanks so much!

      1 Reply Last reply
      0
      • D davecotter

        Re: Dynamically fit QComboBox popup height to the (dynamically changing) count of items

        is there no definitive answer to this? my "dropdown" always has a scroll bar when it doesn't need to:

        0_1564598569571_Screen Shot 2019-07-31 at 11.42.35 AM.png

        How do i tell it to resize just enough such that there's no scroll bar?

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

        @davecotter said in How to size QComboBox popup height to the count of items:

        my "dropdown" always has a scroll bar when it doesn't need to

        Do you mean there is nothing below "kJams 2 (Upgrade from Lite)" to scroll to?

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

        1 Reply Last reply
        1
        • D Offline
          D Offline
          davecotter
          wrote on last edited by
          #3

          no i mean there are a few more items, and there's no reason not to just show them by making the little "window" bigger, without needing a scroll bar

          JonBJ 1 Reply Last reply
          0
          • D davecotter

            no i mean there are a few more items, and there's no reason not to just show them by making the little "window" bigger, without needing a scroll bar

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @davecotter
            I happened to look at sizing of QComboBox dropdown just a few days ago (https://forum.qt.io/topic/105012/qcombobox-specify-width-less-than-content, I'm just going to put some code in there). It turns out it is QComboBox::view() is what you need to fiddle with to adjust dropdown size. I was using QComboBox::view()::setMinimumWidth() for width, you will presumably want something with QComboBox::view()::setMinimumHeight(), or something which sets its size policy to fit instead of scroll if that is available (QSizePolicy??).

            1 Reply Last reply
            7
            • V Offline
              V Offline
              vmanso
              wrote on last edited by
              #5

              The function you are looking for is "maxVisibleItems". Use it to change the number of visible items in the combo box to the total number of items you have.

              1 Reply Last reply
              1
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @vmanso said in How to size QComboBox popup height to the count of items:

                maxVisibleItems

                Beware, the documentation of the function warns about some caveats to take into account for non-editable combo boxes on some platforms.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by
                  #7

                  @vmanso said in How to size QComboBox popup height to the count of items:

                  maxVisibleItems

                  that was it! thanks so much!

                  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