中推广自定义小部件

中推广自定义小部件

本文介绍了如何在 QT Creator 中推广自定义小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

问候,

劳里斯

我玩了很多.现在突然间一个自定义小部件被添加到基类列表中.但是我仍然不知道我是如何添加它的.以及为什么这是列表中唯一显示的自定义小部件.

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.

推荐答案

这似乎是 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:).

这篇关于如何在 QT Creator 中推广自定义小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:44