How to promote a custom widget in QT Creator
This seems to be a bug in Qt Creator. A workaround, oddly enough is to add widgets twice to the list of widgets a widget library exports:
IOSwidgets::IOSwidgets(QObject *parent)
: QObject(parent)
{
m_widgets.append(new aircraftAttitudePlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new alfabeticKeypadPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new arrowedFramePlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new buttonWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new dataButtonPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new frameWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new headingDialPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new imageWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new labelWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new linkedButtonWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new linkedLabelWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new linkedSliderWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new NavButtonPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new numericKeypadPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new repositionWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new runwayInformationPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new slewWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new sliderWidgetPlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new WeightBalancePlugin(this));
m_widgets.append(m_widgets.last());
m_widgets.append(new WindshearMicroburstLateralPlugin(this));
m_widgets.append(m_widgets.last());
}
Hope this saves the next person who runs into this problem, the painstaking effort and the huge amount of time it took me to find this out:).
laurisvr
I really like programming. Having tried a whole bunch of languages. I've settled on C++ as my favorite, but I of course love every single one of them:). Still learning new programming stuff everyday. I love just strolling around this forum and coming across unexpected realms of programming I hadn't even dreamed of existing. Apart from programming I'm also trying to enjoy other aspects of live. Sailing, floorball, playing music and backpacking, ranking high amongst them:).
Updated on June 08, 2022Comments
-
laurisvr almost 2 years
In qt 5.2.1 I've created some custom widgets, like a button. Traditionally there's two ways of doing this. You can either promote an existing widget. And change/add functionality. Or create a custom widget from scratch. I've used the latter.
However, in some cases I would like to use my custom widget, but change some of it's functionality by promoting. The usual way to do this would be to add a widget, and promote it. However, when creating a new kind of promoted widget, a base class has to be picked. And in the dialog where this can be done, only the default widgets are listed.
Is it possible to add a custom widget to this list?
Regards,
Lauris
Edit:
I've played around with it a lot. And now all of a sudden a custom widget is been added to the list of base classes. Yet I still don't know how I've added it. And why this is the only custom widget showing on the list.
-
laurisvr over 9 yearsHi Pavel, Thank you for your answer. It sheds some really good light on how promotion and promotion inheritance works. However in my case I don't want to use inheritance. But I want to promote a custom widget, I've added to QT creator. Do you happen to know how that would work?
-
Pavel Strakhov over 9 yearsThere can't be widgets without any inheritance. They must inherit
QWidget
somehow. If you have a custom widget that inheritsQWidget
directly, you can add a Widget to the form and promote it to the custom widget as usual. -
laurisvr over 9 yearsMy custom widget inherits from qwidget. But rather then using promotion i've created a widget plugin like shown in this link example . This way I've also added properties and stuff like that. But if i were to promote a QWidget these properties wont be accessible. So say I've named my custom widget MySpecialButton, i'd like to promote this widget.
-
Carlton over 7 yearsThanks @Pavel, this explains promotions very clearly. Relevant Qt documentation here.
-
Behzad over 3 yearsI have the same problem, but I did not understand what you did exactly. Could you please give me more details?
-
laurisvr over 3 yearsIt's been a while:), but there's nothing more too it than what I said here. In order for the widget to show up you need to add it twice to the list of widgets being loaded by qtcreator. They might have fixed the bug by now though
-
Behzad over 3 yearsThanks for your prompt reply. Actually, I am working with Qt Creator on Windows and my specific question is that where I can modify the list you mentioned?
-
laurisvr over 3 yearsWell from what I remember, in order to add your own widgets you need to compile Qt creator yourself. Somewhere in Qt creator's code the widgets are being loaded, there you can add your own list.
-
Behzad over 3 yearsOk, I used the Qt Design Custom Widget module in order to do that, so I have not compiled At creator from the scratch.