Adding user built widgets to a ui file in qt creator
Asked Answered
C

2

8

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.

Constantine answered 26/2, 2012 at 18:1 Comment(3)
You can create custom widget for designer: developer.qt.nokia.com/doc/qt-4.8/…Perilymph
Hmm..it looks like if I followed this procedure, anyone who wants to edit this project would have to install the plugin separately, yes? I would preferably like to have it where the project can be opened up itself without installing a plugin, if that's at all possible.Constantine
@LeifAndersen This wouldn't require the plugin to open the project, just to see and interact with the new widget. Depending on your project and team, a central repository for plugins might be a possibility; it's what our company does. I know of no other option besides these, however.Wanting
M
1

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.

Marlea answered 26/6, 2021 at 6:29 Comment(0)
C
2

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.

Cementation answered 16/10, 2012 at 12:47 Comment(0)
M
1

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.

Marlea answered 26/6, 2021 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.