My aim is to create something like contact app, where I can list contacts and choose it to see information about person. I figure out that one of the possible solution is to use QListView + QStyledItemDelegate / QAbstractItemDelegate. The information about it is very difficult so I don't understand it clearly;
(Contact should look something like https://www.sketchappsources.com/free-source/4395-ios-contacts-screen-app-sketch-freebie-resource.html)
So how should I use QAbstractItemDelegate ( I heard that I must reimplement paintEvent )?
I suggest you to start with a data model.
QStandardItemModel
class for beginning and populate it with QStandardItem
class instances. It would allow you to set icon, text, font, background, size and other properties for items. Refer to https://doc.qt.io/qt-5/qstandarditemmodel.html#detailsQListView
using setModel
QListView
's clicked
signal.To render items in more complex way you should
QStyledItemDelegate
class and it's paint
and sizeHint
methods. In the paint
method you should implement rendering and your sizeHint
method should return a valid size for items. Refer to https://doc.qt.io/qt-5/qabstractitemdelegate.html#detailsdata
method of QModelIndex
reference that is passed to paint
method. Use different roles to get appropriate data. Refer to https://doc.qt.io/qt-5/qt.html#ItemDataRole-enumQListView
by setItemDelegate
.Model should be set to QListView and item clicks are handled in same way.