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: • Understanding C++ Type Traits
Episode on KDAlgorithms: • Do Use C++ Algorithms!
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:
• Qt Widgets and more - Tips, Tools, and Tec...
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/m...
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-reso...
About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services
KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrolment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.
Contact us to find out more at [email protected] or visit our website: https://www.kdab.com/software-service...
We are over 100 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/