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 empty space problem
Forum Updated to NodeBB v4.3 + New Features

QListWidget empty space problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.0k Views 1 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.
  • W Offline
    W Offline
    willemf
    wrote on last edited by
    #1

    I use a QlistWidget to show options in a program, like below:

    Screenshot1.png

    However the extra white space at the bottom is ugly to say the least. In theory, a statement such as
    widget->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
    should minimise the size of the widget. In this case it does not.

    Any suggestions?
    Kind regards,
    willem

    1 Reply Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      I believe you need to place your widgets in the layout for that to take effect. https://doc.qt.io/qt-5/layout.html

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      0
      • W Offline
        W Offline
        willemf
        wrote on last edited by
        #3

        The widget is within a layout manager defined in a .ui file.
        At the moment I get by making use of
        sizeHintForColumn(0)
        and
        sizeHintForRow(0)

        But the setSizePolicy() instruction should do it and it does not. Why?

        JonBJ 1 Reply Last reply
        0
        • W willemf

          The widget is within a layout manager defined in a .ui file.
          At the moment I get by making use of
          sizeHintForColumn(0)
          and
          sizeHintForRow(0)

          But the setSizePolicy() instruction should do it and it does not. Why?

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

          @willemf said in QListWidget empty space problem:

          But the setSizePolicy() instruction should do it and it does not. Why?

          That is the $64k question in Qt widgets layout --- let me know if you ever figure how it works! ;-)

          If you do not get a better answer, there is a very old post here, https://forum.qt.io/topic/40717/set-size-of-the-qlistview-to-fit-to-it-s-content/6, which shows user doing it by calculating. Code is against the old ListView, but may work/be adaptable for your purpose?

          1 Reply Last reply
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5

            add a spacer (layout item) at the bottom and then widget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); It's also a property you can set directly in Qt designer

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            4

            • Login

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