Qt equivalent for GTK expander
-
@3beezer said in Qt equivalent for GTK expander:
I just started learning Qt in preparation for porting an application from GTK. I am not finding a widget equivalent to a GTK expander, but I see it in Qt Designer. What is the widget in the attached image with the text "Display Widgets"?
Hi @3beezer, and welcome!
Have a look at
QToolBox
. It shows 1 child at a time -- does that suit your needs?If I'm not mistaken, the Qt Designer expander for "Display Widgets" is custom code. I can look up the code if QToolBox isn't suitable.
-
QToolBox is at least close. It appears to provide the same functionality, but the appearance is quite difference. I like the appearance of the widget in Qt Designer better. If it is custom, is it possible to get the code? I am using PySide2, but I suppose I could translate C++ code.
I found a lot of postings from people looking for such a widget. Your response suggesting a QToolBox comes closer than any other I have seen, which all suggested a custom solution. It is surprising to me that such a widget is not standard considering how many widgets there are in Qt. It is also surprising that there seems to be no gallery of all the widgets showing them in action. Such a thing would be very helpful to beginners like me. The Widget Box in Qt Designer is the closest thing I have found. The documentation sometimes has an image, but not always. Is there an app that displays all the widgets and permits them to be operated?
Thanks for the suggestion.
-
Hi,
The source of Qt Designer is in the qttool module that you can either get through the Maintenance Tool if you installed Qt using the online installer or clone it from https://code.qt.io
-
@3beezer said in Qt equivalent for GTK expander:
QToolBox is at least close. It appears to provide the same functionality, but the appearance is quite difference. I like the appearance of the widget in Qt Designer better.
Try customizing the style of a
QToolBox
first:- https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbox
- https://doc.qt.io/qt-5/stylesheet-reference.html
is it possible to get the code?
Yep. It's the
WidgetBox
in Qt Designer: https://code.qt.io/cgit/qt/qttools.git/tree/src/designer/src/components/widgetboxThe
WidgetBox
reads widgetbox.xml and uses the data to dynamically populate itself. The GUI is mainly in theWidgetBoxTreeWidget
Here's an interactive code browser, but it only shows the *.h and *.cpp files: https://code.woboq.org/qt5/qttools/src/designer/src/components/widgetbox/
I suppose I could translate C++ code
If you don't like styling or the
WidgetBox
code, there's also the option of using aQTreeView
orQTreeWidget
.It is surprising to me that such a widget is not standard considering how many widgets there are in Qt.
You could suggest a feature at https://bugreports.qt.io/
It is also surprising that there seems to be no gallery of all the widgets showing them in action. Such a thing would be very helpful to beginners like me... The documentation sometimes has an image, but not always. Is there an app that displays all the widgets and permits them to be operated?
You're right, such an example would be useful. Unfortunately, it doesn't exist.
Here are some alternatives:
- List of all widget classes: https://doc.qt.io/qt-5/widget-classes.html
- Gallery code for Qt Quick Controls 2: https://doc.qt.io/qt-5/qtquickcontrols-gallery-example.html
-
The expander is just a specialization of a "tree view" node, right? maybe see if the tree view classes can provide what you want.
-
I thought I should mention for the benefit of any readers also seeking such a resource that Summerfield "Rapid GUI Programming with Python and Qt" contains in Appendix B a gallery of some Qt widgets. This book is out of date because it is based on PyQt 4, but I still find it to be very helpful. His discussions of program structure, methodologies, techniques, and philosophies are still very current, and the numerous program examples may be out of date, but they are close enough to be informative. "Hands-On Qt for Python Developers" is current -- it appeared late May 2019 -- but it contains little of this sort of information.