Introduction to Qt Widgets (Part 55) - Accessing Data
In the previous episode we saw the very high level view of model/view. So, we will now start our decent 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.
About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.
Every month our newsletter is featuring technical blogs on Qt, C++ and 3D topics: https://www.kdab.com/development-resources/sign-up-for-our-newsletter/
About KDAB:
Trusted software excellence across embedded and desktop platforms
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications. In addition to being leading experts in Qt, C++ and 3D technologies for over two decades, KDAB provides deep expertise across the stack, including Linux, Rust and modern UI frameworks. https://www.kdab.com/software-services.
KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt/QML, Modern C++, Rust and OpenGL. https://training.kdab.com/
With 100+ employees from 20 countries and offices in Sweden, Germany, USA, France and UK, we serve clients around the world. https://www.kdab.com/about/contact/