[Solved] Design a toolbar/widget in a separate .ui and add it to the QMainWindow
-
wrote on 13 Jan 2012, 09:22 last edited by
Hi all,
I have an application that load some plugins and I would like one of these plugins to add a new QToolbar when loaded.
Is it possible to define this toolbar with Designer in a standalone .ui and then use it from my plugin (not dynamically with QUiLoader)?Same question with a QDockWidget.
Thanks a lot for your help!
-
wrote on 13 Jan 2012, 11:48 last edited by
Yes, this is possible. If you use resources, make sure the they're "initialized":/doc/qt-4.8/resources.html#using-resources-in-the-application eventually.
-
wrote on 13 Jan 2012, 12:05 last edited by
I don't understand the link with resources?
Regarding my original question: how do I build a ui with the top-level widget beeing a QToolbar in Designer?
-
wrote on 13 Jan 2012, 20:21 last edited by
I edited a ui to keep nothing but the QToolbar. It's still possible to open and edit it with Designer. I don't know if it is a correct way to work, is it?
@<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>toolBar</class>
<widget class="QToolBar" name="toolBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>552</width>
<height>273</height>
</rect>
</property>
<property name="windowTitle">
<string>toolBar</string>
</property>
<action name="actionSample_1">
<property name="text">
<string>sample action</string>
</property>
</action>
<action name="actionSample_2">
<property name="text">
<string>sample #2</string>
</property>
</action>
<addaction name="actionSample_1"/>
<addaction name="actionSample_2"/>
</widget>
<resources/>
<connections/>
</ui>@ -
wrote on 13 Jan 2012, 22:28 last edited by
Ah, I see. A single [[Doc:QToolBar]] cannot be edited in Qt Designer. But to be honest, it doesn't give you much benefit. It's so easy to add actions with icons to a toolbar programmatically that it's not worth the work in a graphical design tool. addAction(), insertAction(), add/insertSeparator() are your friends here.
-
wrote on 20 Jan 2012, 08:52 last edited by
The idea was to let someone else design the toolbar without a line of code.
But I found a solution. I created a mainwindow, added a toolbar. Then edited the xml to remove everything but the toolbar.
Now I have a ui that can still be edited by Designer. -
wrote on 20 Jan 2012, 10:19 last edited by
Nice trick! Thank's for sharing!
1/7