Search code examples
qtqt-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. 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?


Solution

  • First, make sure you have the Q_OBJECT macro in your class definition. Also, make sure the file was properly moced. 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.