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. Limit height of the QListWidget to accomodate only single row

Limit height of the QListWidget to accomodate only single row

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetsizepolicysizehintsize
6 Posts 3 Posters 1.2k 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.
  • V Offline
    V Offline
    voltron
    wrote on 24 Dec 2022, 09:59 last edited by
    #1

    I have a QListWidget which always shows three items with icons aligned from left to right. Despite this the height of the widget is too big and it looks ugly and occupies too much space.
    a2a1196f-409b-4f37-bda4-7c5343a9ae41-image.png
    Is it possible to make list widget show only single row, something like in the image below
    1a9bff44-a95d-4a0a-a89c-2e83c3eeb56b-image.png
    I tried to play with the sizePolicy property to make it smaller, but could not get desired result. Also I do not want to hardcode size, as it might not work correctly with different themes/dpi/font or icon sizes.

    Any ideas how to achieve this?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 24 Dec 2022, 10:07 last edited by
      #2

      You have to manually set the size of your QListWidget to your desired size. It will not resize automatically to the size of the contents.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      V 1 Reply Last reply 25 Dec 2022, 06:36
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 Dec 2022, 11:46 last edited by
        #3

        Hi,

        Beside the suggestion of @Christian-Ehrlicher, are you using a layout ?

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

        V 1 Reply Last reply 25 Dec 2022, 06:38
        0
        • C Christian Ehrlicher
          24 Dec 2022, 10:07

          You have to manually set the size of your QListWidget to your desired size. It will not resize automatically to the size of the contents.

          V Offline
          V Offline
          voltron
          wrote on 25 Dec 2022, 06:36 last edited by
          #4

          @Christian-Ehrlicher thanks, but if I understand correctly (and as mentioned in the starting post), this way it will not work correctly with different themes/font sizes/screen dpi. Or am I miss something?

          1 Reply Last reply
          0
          • S SGaist
            24 Dec 2022, 11:46

            Hi,

            Beside the suggestion of @Christian-Ehrlicher, are you using a layout ?

            V Offline
            V Offline
            voltron
            wrote on 25 Dec 2022, 06:38 last edited by
            #5

            @SGaist yes, of course I do use the layout. In this specific case QListWidget lives inside a QVBoxLayout together with some other widgets.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              voltron
              wrote on 25 Dec 2022, 08:35 last edited by
              #6

              Kind of solved. If I set sizeAdjustPolicy to AdjustToContents and sizePolicy to Maximum, the list widget size will adjust to accomodate items plus small margins around them. I'm quite happy with the result, it would be even better if I could make items equally distribute across available space, but even now it looks good enough.

              1 Reply Last reply
              0

              6/6

              25 Dec 2022, 08:35

              • Login

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