PDA

View Full Version : Custom Widget in QListWidgetItem in QListWidget, QListWidgetItem doesn't resize



TestCoder
21st May 2020, 16:39
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.

13451

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.

13452

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

ChrisW67
23rd May 2020, 07:44
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 (https://doc.qt.io/qt-5/qtwidgets-dialogs-extension-example.html)

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.