Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
3 August 2022
QListView, QTableView and QTreeView can all be configured via a number of roles from the models, e.g. BackgroundRole, ForegroundRole, FontRole, and TextAlignmentRole. This often means that no additional configurations of the views are needed.
However, if you want more control over how the data is presented, you can get that by implementing a delegate.
The question, however, is: Which delegate should you subclass from - QItemDelegate or QStyledItemDelegate? The documentation argues the latter, but the answer isn't so black and white. In this video I'll look into many details, and at the end implement a new super class which is super easy to extend.
0:00 Introduction
0:47 When do you /not/ need a delegate?
2:33 Rendering Money instances in a delegate without a custom delegate
4:21 Difference between QItemDelegate and QStyledItemDelegate
6:56 QStyledItemDelegate with Oxygen style
7:59 Subclassing QStyledItemDelegate
11:00 Debugging into QStyledItemDelegate
15:00 Subclassing QItemDelegate
19:06 Paint negative numbers in red
20:55 QWAMDelegate
22:49 What's in the next two episodes?
Links:
* Avoid wrapping the money instance in QVariant::fromValue() - https://youtu.be/rL8gYFPcFlE?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/Delegates
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI