Qt – Adding user built widgets to a ui file in qt creator

qtqt-creatorqt-designerqt4

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.

Best Answer

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.

Related Topic