QT Widget ListView with Custom Designed Items
-
Hi
Normally you would use a delegate to draw it as you want it to look
http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
(this is kinda a trick as it only draws as widgets until you edit the row, then its
live widgets. but it has good performance.)Alternatively for only a FEW items, one can use
http://doc.qt.io/qt-5/qlistwidget.html#setItemWidget
(and a ListWidget )
Here we simply put a live widget on top of the row item.
This has bad performance with many items and on small boards/phones.Alternatively for a few items, you can use
a QScrollArea.In most cases you will be most happy with a model and a view and a delegate as you can share the model with more views and its fast.
-
@mrjj Thank you for your reply, i tried to understand stardelegate example but its bit overwhelming for me as a new user.
So my question is Cant we use visual custom widget as a delegate instead of overriding Paint method and design it with pure code? -
@scotryder
The setItemWidget can be used to inset a widget ( with subwidgets ) on a item but
its not possible to use as a delegate as such.
This method is very easy but also a bit heavy with many items.
But on a desktop class pc. many items is maybe a thousands.
So if app is not to run on smartphone/ Pi boards then it works pretty ok.
However, the delegate and painting is best in terms of memory use and performance.