Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to promote a custom widget in QT Creator

Tags:

c++

widget

qt

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.

like image 986
laurisvr Avatar asked Sep 05 '14 10:09

laurisvr


People also ask

How do I create a custom widget Qt?

Adding the Custom Widget to Qt Designer. Click Tools|Custom|Edit Custom Widgets to invoke the Edit Custom Widgets dialog. Click New Widget so that we are ready to add our new widget. Change the Class name from 'MyCustomWidget' to 'Vcr'.

Should I use Qt Quick or Qt widgets?

Qt Widgets provide means for customization via style sheets, but Qt Quick is a better performing choice for user interfaces that do not aim to look native. Qt Widgets do not scale well for animations. Qt Quick offers a convenient and natural way to implement animations in a declarative manner.

What is widget in Qt Designer?

Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.

What is Qt stacked widget?

QStackedWidget can be used to create a user interface similar to the one provided by QTabWidget. It is a convenience layout widget built on top of the QStackedLayout class. Like QStackedLayout, QStackedWidget can be constructed and populated with a number of child widgets ("pages"):


1 Answers

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:).

like image 55
laurisvr Avatar answered Oct 11 '22 21:10

laurisvr