Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt designer reading xml(.ui) file implementation
I have a requirement where i need to read an xml file which specifies the layout and position of the widgets in a Form/QMainWindow.
Since Qt designer also works in the same way i.e reading from the xml structure in .ui file and loading it to the frame/widget.
Where can i find the above implementation I checked "QUiLoader.cpp":http://qt.gitorious.org/qt/qttools/blobs/ad9b37a706567147b78d22d0de4a016b6c5af9b3/src/designer/src/uitools/quiloader.cpp. but could not understand much.
Thanks in advance.
Note: With my own implementation I am able to read the xml file and load the widget to the form for single Layouts like QGridLayout , QFormLayout etc. I need an idea for the implementation of multiple layouts like a QGridLayout has a QHboxLayout etc.
andre last edited by
I don't know what your real question is here. You could implement your own scheme of course, but why would you? [[doc:QUiLoader]] can do it for you, based on standard .ui files that you already own a complete editor for: QtDesigner/QtCreator. It seems to me that it is harder to create your own system, than to spend the effort to learn about using QUiLoader by reading its docs and doing some experiments.
Here the xml file consists of my own custom widgets. for eg:-
@<?xml version='1.0' encoding='UTF-8'?>
<Attribute name="WindowsTitle" value="Some Values For Parent Widget"/>
<Attribute name="HeaderTitle" value="Dummy Screen"/>
<Layout type="Grid" name="mainLayout">
<Component type="Frame" name="frameTop">
<Position row="0" col="0" rowSpan="1" colSpan="3"/>
<Layout type="Grid" name ="upperLayout">
<Layout type="Horizontal" name="hBox" stretch="80">
<Position row="0" col="2" rowSpan="1" colSpan="1"/>
<Component type="Label" name="labelUser">
<Text alignment="TopCenter" textNo="100">User# </Text>
<Component type="LineEdit" name="lineEditUser">
<Text> 1 </Text>
<Component type ="Label" name="labelFullName" >
<Position row="1" col="1" rowSpan="1" colSpan="1" />
<Text alignment="TopCenter" textNo="101"> User Login </Text>
<Component type ="LineEdit" name="lineEditFullName" >
<Position row="1" col="2" rowSpan="1" colSpan="2" />
<Text> Test </Text>
So the requirement is that at the runtime I am going to read the xml file and add the same to a Form. For the custom widget there are other attributes/properties as well. So for the implementation I was thinking to get an idea how the QUiLoader class works ?
andre last edited by
You're still not asking a question.
Sorry I might not be clear with my question. I want to know how the QUiLoader reads the xml file(.ui) and loads the widgets to the form i.e I want to generate a panel/frame thats contain the widgets specified in the xml file at the particular position based on the layouts. Then this panel/frame is added to the main module/application/frame.
The steps that i follow are.
- Reading the xml file using QXmlStreamReader.
- Storing the components/widgets to a container.
- Storing the attributes of the components/widget to another container.
- Then based on the layout , adding the component/widgets to the frame.
Problem is to handle multiple layouts. Also i want to know if this is the correct approach or not ?