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 do I tell QListView to resize to fit?
QtWS25 Last Chance

How do I tell QListView to resize to fit?

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

    I have a QListView and have assigned a model and a delegate. I am using it to display images in a horizontal bar as below

    !http://i.stack.imgur.com/8aBJC.jpg()!

    On a user event, data is updated in the model. One such event causes the width of the images to be reduced like below(#4).

    !http://i.stack.imgur.com/iFPYf.jpg()!

    I emit a dataChanged on the corresponding index and only the concerned widget is repainted. Because of this, there is a gap between #4 and #5 which does not get filled. I am thinking that there must be a way to refresh all visible rows - but am unable to find it.

    I tried the following, but they do not work:

    @1. viewport()->updateGeometries()
    
    2. viewport()->update()
    
    3. I tried changing the width to see if it refreshes
        int curWidth = mp_mylistview->width();
     this->mp_mylistview->setFixedWidth(curWidth + 1);
     this->mp_mylistview->setFixedWidth(curWidth);@
    

    Any suggestions?

    Note: The above images are samples for illustration and not the originals. If you need code, I will need to filter out confidential information before posting it.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on last edited by
      #2

      Are you implying that the gap between row 4 and 5 should not be there?
      What about when you iconify and re-show the window, does that gap go away?

      I think each column is normally set to the same width, so I'm not sure what the problem is...

      ps. you might want to look at newer tech, like QML for easier ways to display this :)

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

        @Thomas Yes. I need the elements to the right to shift left to occupy the space( and a new one show up if space is available). No, minimizing and restoring does not remove the gap, but if I close the widget and reopen, it fills up the gap. No, the width of each column is variable.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          What role(s) are you updating in your model? Just the DecorationRole, or also the SizeHint role?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            go4sri
            wrote on last edited by
            #5

            @Andre I have a custom delegate with the paint() and sizeHint() methods implemented. I do not have a sizehint role within data. I have the following custom roles:

            1. IconRole - returns a qpixmap
            2. WidthRole - returns the width of the pixmap
            3. LabelRole - returns the label to be displayed below the image

            The WidthRole returns the updated width.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              go4sri
              wrote on last edited by
              #6

              I had to emit the @layoutChanged()@ signal after the @dataChanged()@ signal.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Ah, that makes sense I guess. Thanks for reporting back!

                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