如何在QT Creator中升级自定义小部件

lau*_*svr 5 c++ qt widget

在qt 5.2.1中,我创建了一些自定义小部件,例如按钮。传统上,有两种方法可以做到这一点。您可以升级现有的小部件。以及更改/添加功能。或从头开始创建自定义窗口小部件。我用了后者。

但是,在某些情况下,我想使用我的自定义窗口小部件,但是通过升级来更改其某些功能。通常的方法是添加一个小部件并对其进行升级。但是,在创建一种新型的提升小部件时,必须选择一个基类。在可以完成此操作的对话框中,仅列出默认的小部件。

是否可以在此列表中添加自定义窗口小部件?

问候,

劳里斯

编辑:

我已经玩了很多。现在突然将自定义小部件添加到基类列表中。但是我仍然不知道如何添加它。以及为什么这是列表上显示的唯一自定义窗口小部件。

lau*_*svr 1

这似乎是 Qt Creator 中的一个错误。奇怪的是,一种解决方法是将小部件两次添加到小部件库导出的小部件列表中:

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());
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助下一个遇到这个问题的人,避免我花费大量的精力和时间来找出这个问题:)。