Important: Please read the Qt Code of Conduct -

[Solved] Design a toolbar/widget in a separate .ui and add it to the QMainWindow

  • 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!

  • 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.

  • 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?

  • 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">
    <widget class="QToolBar" name="toolBar">
    <property name="geometry">
    <property name="windowTitle">
    <action name="actionSample_1">
    <property name="text">
    <string>sample action</string>
    <action name="actionSample_2">
    <property name="text">
    <string>sample #2</string>
    <addaction name="actionSample_1"/>
    <addaction name="actionSample_2"/>

  • 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.

  • 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.

  • Nice trick! Thank's for sharing!

Log in to reply