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. QListWidget: is there a way to set the number of visible rows?
Forum Update on Monday, May 27th 2025

QListWidget: is there a way to set the number of visible rows?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 420 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.
  • idlefrogI Offline
    idlefrogI Offline
    idlefrog
    wrote on last edited by idlefrog
    #1

    When I create a QListWidget is sizes itself according to it's hint values, but is there a standard way to set the height so that N items are visible?
    I'm guessing I will have to get the height of each row, and overload sizeHint.
    (As in Resize QListWidget in scroll area)?

    A setVisibleRows(int) method would be nice.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      As far as I know, there is not.

      1 Reply Last reply
      0
      • idlefrogI Offline
        idlefrogI Offline
        idlefrog
        wrote on last edited by idlefrog
        #3

        Thanks @mrjj ... That's what I thought... in the end I did something like this:

        QSize MyListWidget::sizeHint()
        {
            auto size = QListWidget::sizeHint();
            int h = sizeHintForRow(0) * m_rows_visible;
            size.setHeight(h);
            return size;
        }
        
        1 Reply Last reply
        1

        • Login

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