Leif Andersen
Leif Andersen

Reputation: 22342

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.

Upvotes: 8

Views: 7315

Answers (2)

Jason C
Jason C

Reputation: 40396

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.

Upvotes: 1

Alberto
Alberto

Reputation: 728

I'm not sure to understood your question well so I could ask the wrong question. Are you sure your "B" widget is a subclass of QDesignerCustomWidgetInterface? This should expose all stuff that your widget/plugin offers...

Last note: a friend of mine tried to add a custom widget like you. And at the end of the described procedure that Lol4t0 told you, he found you must compile plugin with the same compiler with wich qtcreator/designer was compiled. This happens because as we know c++ doesn't keep ABI compability (instead of i.e. C language) stuff like: Name handling can change from compiler to compiler, how data is loaded into registers can change...and so on. My friend tried to compile plugin with mingw, but he found that qtcreator was compiled with visual studio compiler. Therefore if you want to deploy your plugin on Windows or you compile your plugin with visual studio, or you have to compile qtcreator/designer from scratch.

Upvotes: 2

Related Questions