S
S
sinoptis2018-11-30 22:03:24
Qt
sinoptis, 2018-11-30 22:03:24

Qt custom controls. How to create properties?

I want to create a custom button that will have an additional digit field.
digitbutton.h

#ifndef DIGITBUTTON_H
#define DIGITBUTTON_H

#include <QPushButton>

class DigitButton : public QPushButton
{
    Q_OBJECT
    Q_PROPERTY(int digit MEMBER m_digit)

public:
    DigitButton(QWidget *parent = nullptr);
private:
    int m_digit;
};

#endif // DIGITBUTTON_H

digitbuttob.cpp
#include "digitbutton.h"

DigitButton::DigitButton(QWidget *parent) : QPushButton (parent)
{

}

The property is not displayed in the designer, he just does not see this class
5c01891048aa6982516428.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Sorokin, 2018-11-30
@Vass

In order for your class to appear in the designer, you need to write a plugin for the designer that will display it there.
In the Qt documentation, everything is pretty detailed.
You can start with this example doc.qt.io/qt-5/qtdesigner-customwidgetplugin-examp...
well, follow the links.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question