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. Fit QListWidget to content

Fit QListWidget to content

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.3k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    What's the recommended technique to fit a QListWidget to the width/height of its content? I'd like to have a dynamic list widget that uses no scrollbars and always shows all its elements. I need to know what to resize to prior to showing the ListWidget.

    Why is "contentsRect" for a ListWidget returning clearly inaccurate information? even when called for an initialized and visible list widget, full of my own rows? It's ~ 30% wrong on both height and width.

    Is there any API call that's accurate?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      ronM71
      wrote on last edited by
      #2

      I ended up using a combination of item.count * GridSize.height for the height and a QFontMetrics to evaluate the width of the text, with some hard coded provisions for the icon size i'll be using + some extra padding.

      Still, I can't help feeling this is a hack. Am I missing some 'right way' of doing this?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        I currently have no idea on how to get the size of the content. What could work is to get the size of the data model, but then you are missing the sizes that are added by the view (e.g. spaces between items etc.).

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hareen Laks
          wrote on last edited by
          #4

          Hi,

          is there no solution for this problem yet?

          I have a QListView which is filling using a model. But my QlistView height is far greater than the size of the contents. In other words, even it consist only two items it shows listview with amount of space for 10 or 15 items. I want to fit the size of the ListView to contents.

          How can I do that?

          Thanks..

          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