简体   繁体   English

向Qt Designer添加自定义小部件

[英]Adding a Custom Widget to Qt Designer

I've got the following custom widget: 我有以下自定义小部件:

class QDESIGNER_WIDGET_EXPORT MySpecialButton : public QAbstractButton
{
    Q_OBJECT
    ...etc...
};

Qt Designer recognizes this widget, and I can place it onto my form without a problem. Qt Designer可以识别此小部件,因此我可以毫无问题地将其放置在表单上。 However, when looking in the property editor, only the QObject and QWidget properties are visible. 但是,在属性编辑器中查看时,仅QObject和QWidget属性可见。 How do I get Qt Designer to recognize that this is also a QAbstractButton object? 如何让Qt Designer识别这也是QAbstractButton对象?

First, make sure you have the Q_OBJECT macro in your class definition. 首先,请确保您在类定义中具有Q_OBJECT宏。 Also, make sure the file was properly moc ed. 此外,确保文件正确的是moc版。 If neither of those help, you might investigate how QPushButton and QToolButton are declared to see if that gives you any hints. 如果这些都QPushButton ,您可以调查如何QPushButtonQToolButton ,以查看是否有任何提示。

Finally, if you need a chainsaw approach rather than a scalpel, you could define the properties you want to set in your class, giving the QAbstractButton functions as the ones to call for the properties. 最后,如果需要链锯方法而不是手术刀,则可以定义要在类中设置的属性,并为QAbstractButton函数提供调用该属性的功能。 Look into the Q_PROPERTY macro. 查看Q_PROPERTY宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM