Search code examples
qtqt4qt-creatorqt-designer

Adding user built widgets to a ui file in qt creator


The qt designer portion of qt creator has many built in widgets. But let's say I want to add custom widgets created in the same qt project to the ui file of the window. By taking these steps:

  1. Create a new Qt GUI application with a main window, we'll call the window A.
  2. Add a new widget to the project, the widget just uses standard UI components, say buttons. We'll call this widget B.
  3. Add an instance of widget B to window A.

Now, I know one way to do that, and that is:

  1. In window A, add a blank widget (or widget container, from the containers section of the list of possible widgets. We'll call this widget C.
  2. Promote it (widget C) to widget B.

However, the problem with this is that Qt Creator's designer treats it like a generic QWidget. And as such, you can't do things like add it to a splitter, or connect signals/slots that are specific to the widget.

So is there any other ways to add widget B to window A in the ui file using qt creator? Thank you.


Solution

  • I know this is a very old question, and I'm not sure what capabilities Designer had in 2012, but I came across this in a Google search for something else and figured I'd add some missing info:

    However, the problem with this is that Qt Creator's designer treats it like a generic QWidget. And as such, you can't do things like add it to a splitter, or connect signals/slots that are specific to the widget.

    Generic QWidgets can be added to splitters with no issues these days.

    As far as signals and slots go, you can use them like so:

    1. After promoting a widget to your custom widget, right-click it and choose "Change signals/slots..." from the context menu.
    2. Add the signatures for any custom signals and slots you want to be able to use in Designer / Creator here.

    Now those signals and slots will be accessible in Designer like any other signals and slots.

    The only thing you can't really get with promoted widgets is access to custom properties in the property panel; for that, yeah, you'll need to go through the custom widget creation process.