Results 1 to 2 of 2

Thread: Custom Widget in QListWidgetItem in QListWidget, QListWidgetItem doesn't resize

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Custom Widget in QListWidgetItem in QListWidget, QListWidgetItem doesn't resize

    Hello,
    i have a simple custom widget multiple times in a QListWidget.
    The custom widget contain some buttons and other suff and a QTableView,
    whitch is hidden in the first place.

    TwoItems.png

    The button "Show/Hide TableView" will toggle the visibility of the QTableView.
    But when the visibility is set to true, the widget doesn't resize.
    In the next picture i clicked once the button "Show/Hide TableView" and the
    QTableView will be visible (small white bar), but the surrounding QGroupBox
    doens't change it's size and therefore also not the QListWidgetItem.

    TwoItems_NoStretch.png

    What i need:
    - a widget based list view (i have used QListWidget)
    - custom widgets which may change in size (e.g by setting the visibility of childs)

    Can anyone help why my example doesn't work? (see Zip file)

    Thx
    Stefan
    Attached Files Attached Files
    Last edited by TestCoder; 21st May 2020 at 17:44.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Custom Widget in QListWidgetItem in QListWidget, QListWidgetItem doesn't resize

    The first part of the problem is to get TestWidget to resize itself properly in isolation. The secret to this is the QLayout::SetFixedSize size constraint on the top-level layout of the TestWidget.
    See the Extension Example

    The second part of the problem is to have the list view resize its rows when one of the child widgets changes size (up or down). I do not have an obvious way to do this off the top of my head. It will resize rows if the QListWidget itself is resized, but that would be a nasty hack. Calling update() on the QListWidget when the child widget resizeEvent() is called does work either.

    You may need to make your own "list" out of a QScrollArea, QWidget, and QVBoxLayout to gain the control you need.

Similar Threads

  1. QListWidget and QListWidgetItem
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 3rd August 2011, 10:59
  2. Replies: 1
    Last Post: 22nd July 2010, 05:58
  3. Replies: 1
    Last Post: 11th May 2010, 03:52
  4. delete QListWidgetItem in QListWidget
    By sophister in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2009, 16:52
  5. QListWidget add QListWidgetItem
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2006, 20:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.