How to resize QListView row to index widget size
I have custom model(
ListModel), which contains
AbstractModel*. From the
AbstractModelare inherited 3 models :
Chat. Each of the models have own view (
***View). I need to set my model(
ListModel) and set for each item(index for
QListView) own view. But when I set view (
QListView::setIndexWidget) row height remains default.
How to make the height of the row equal to the height of its view(views can resize dynamically)?
sizeHintForRowmethod, but it never calls.
From Qt docs: "Note that to control the height of a row, you must reimplement the
QAbstractItemDelegate::sizeHint()function". But I can't get access to index widget from delegate.
What I can do?
QAbstractItemDelegate::sizeHint() function". But I can't get access to index widget from delegate.
The index is the second argument of sizehint... http://doc.qt.io/qt-5/qabstractitemdelegate.html#sizeHint
@VRonin yes ,I can get a model by index, but I can not get a view by index or model. I need view because I can get item widget only when I call
view-> indexWidget(), isn't it?.
Nope, the delegate replaces the
What kind of widgets are you using? are they simple Qt widgets or are they composite?
@VRonin I'm using composite custom widgets. Yep, you right, delegate replaces
indexWidget, but I don't understand how show my custom widget for display, not for edit.
I.e., I need to all widgets are always visible, not only when edit requested
Actually, I do not need editing at all. I need only show widgets and use them
Please tell me how this can be done, if you know. Because I google it for 3 days. And I didn't find the right answer. The
createEditormethod shows the widget only for editing.
It's not a trivial task. If your model is not huge you could use something like this: https://pastebin.com/XrppLZ3m but, in general, you'd have to manually handle the painting
@VRonin Ty, it's works, what I should read to better understand Model / View / Delegate programming? I read all the documentaition on qt.io about this theme, but I did not see anything even remotely resembling such an approach.
P.S. It is normal to set new delegate for each item if I need to show heterogeneous data in list?
what I should read to better understand Model / View / Delegate programming?
Basically everything I know comes from Advanced Qt Prgramming: Creating Great Software with C++ and Qt4
It is normal to set new delegate for each item if I need to show heterogeneous data in list?
No. What I would do is create a QStackedWidget with the possible combinations, use that as base and display the correct page based on the data in the index