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
18 April 2025
In the previous episode we saw the very high level view of model/view. So, we will now start our descent towards actual code, but on the way there we will discuss two very crucial things, namely:
- How do we address the individual items in the views (for a table it is simple: (row 12, column 15), but how about a tree?
- What properties can we get for each cell? (the answer includes: the text, its foreground and background color, and much much more).
Chapters:
00:00 Welcome
00:29 Understanding why we need model indexes.
06:10 Wrapping the void pointer in a class - QModelIndex
07:08 The API for QModelIndex
07:32 QModelIndex::isValid()
11:57 QModelIndex::model()
12:56 The code inside QTreeView - addressing the data
15:27 Getting to the data - item roles
17:40 Why only a data method, and not text, icon, text color methods?
19:47 Edit Role vs. Display Role
21:37 Why is it so difficult?
23:33 Advertise: Multi-threading training
23:50 QPersistentModelIndex
27:14 What's next?
Links:
* KDAB Multi-threading Training Course: https://training.kdab.com/portfolio/in-depth-multithreading-with-qt/
The example code showcased in this video is available here:
https://github.com/KDABLabs/kdabtv/tree/master/Programming-With-Qt-Widgets/modelview
All 'Introduction to Qt Widgets - Module 1' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6hgf7zCKF2Rv9Y0WoN8RVGf
All 'Introduction to Qt Widgets - Module 2' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6j_c41CFMprvg9EiWz0WdSy
All 'Introduction to Qt Widgets - Module 3' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6hWZO_viEf1rfjgk4E6SCKd
All 'Introduction to Qt Widgets - Module 4' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6iXUNQMb2GkEjV_oK6Xid9-
All 'Introduction to Qt Widgets - Module 5' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6h1tsLAETdrrFlsVMeYpiHI
All 'Introduction to Qt Widgets - Module 6' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6jIsRYriqN70V83t_mdDZHT
All 'Introduction to Qt Widgets - Module 7' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6hHyqD9ZxUqpd14LoHvadN7
All 'Introduction to Qt Widgets - Module 8' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6iCb8g5NSfVqX0JRFzFnxak
Please note that non-English dubs for all KDAB videos are auto-generated. These translations have not been moderated by us and may contain inaccuracies. We appreciate your understanding and apologize for any confusion this may cause.