Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt object/class to Qt ui file

This may seem like a very strange question but is it possible to generate a Qt Designer form (.ui) from a Qt object, say something that inherits QWidget?

My plan is to build a simple dynamic form in code as the user picks what stuff they want e.g fields, type of control and then dump out a .ui file so that they can tweak the layout if needed after.

The code will then use the QUiLoader class to reload the ui file and show the modified or not ui file.

like image 895
Nathan W Avatar asked Nov 17 '11 04:11

Nathan W


2 Answers

The Qt-Introspection tool GammaRay can save dialogs from the AUI (Application Under Inspection) to .ui files in its latest version, IIRC.

like image 54
Marc Mutz - mmutz Avatar answered Oct 20 '22 04:10

Marc Mutz - mmutz


Since QWidget inherits from QObject, it gets all of the dynamic property inspection QObject provides. QObjects (and QWidgets) also naturally arrange themselves into trees (see QObject::parent and QObject::children). By following the tree of widgets, and getting the properties of each one, you can generate an xml .ui file containing the basic info about each control.

Working out the signal/slot connections from a pre-established form might be a bit more tricky, since there doesn't seem to be any way to get information on them besides QObject::dumpObjectInfo but for the program you describe in your question it's easy enough to keep track of them some other way.

like image 41
Tyr Avatar answered Oct 20 '22 05:10

Tyr