简体   繁体   中英

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. However, when looking in the property editor, only the QObject and QWidget properties are visible. How do I get Qt Designer to recognize that this is also a QAbstractButton object?

First, make sure you have the Q_OBJECT macro in your class definition. Also, make sure the file was properly moc ed. If neither of those help, you might investigate how QPushButton and QToolButton are declared to see if that gives you any hints.

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. Look into the Q_PROPERTY macro.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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