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
12 July 2023
QLineEdit has it, QTextEdit has it too, but QComboBox doesn't... I'm talking about a setReadOnly method.
So, how do you make a QComboBox (and for that matter all other widgets without a setReadOnly method) read only?
They all have setEnabled(), but that truly disables the widgets, so you can for example not switch tab in a tab widget, or scroll a QListView, so that is not the cure.
Watch this episode to learn how.
Links:
* C++ Type traits: https://youtu.be/LzkxgfvvHqY?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
* Episode on KDAlgorithms: https://youtu.be/iAEIPk64ZJw?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
* Download KDAlgirithms: https://github.com/KDAB/KDAlgorithms
0:00 Introduction
1:19 Readonly is different from disabled!
2:08 Initial idea for a solution - an event filter which blocks everything but a few selected events
4:00 event filter which lets everything through minus mouse and key events
7:35 Using SFINAE to test for if a widget has a setReadOnly method - FAIL
8:57 Checking if a widget has the readOnly property
10:37 Making it possible to enable some widgets
12:21 A warning on the way out.
All Qt Widgets and more videos:
https://www.youtube.com/playlist?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/ReadOnly