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
25 May 2023
In my application, I have a lot of QTableViews and a lot of QTreeViews. A lot of them have context menus.
Now, here was my problem: How could I set up those context menus without sub-classing each time?
Sure, I could connect to the signal customContextMenuRequested, but that didn't work well when I wanted to have some context menu shared for all tables and trees.
In this episode, I'll present a solution where I do not need to add a new subclass each time I want a custom context menu.
Further, I'll discuss a problem I had with the syntax, where lots of std::unique_ptrs got in the way. The solution to that problem got inspired by type erasure, but first I had to give up on one of my fundamental beliefs in C++ programming, which said "never hand over an instance of a class which has virtual methods"
Segments:
0:00 Introduction
0:19 How to add a context menu at all?
1:24 Why create my own framework?
2:37 Using the framework
3:05 Setting up the actions
4:50 The Action classes
5:56 Sub menus and separater
8:30 Library of predicates
10:44 A "meta" predicate - nice use case!
12:56 Stay tuned for next episode where the code will be improved.
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI