Big_Stone88
15th April 2016, 07:57
Hello to all:-)
I have a question about the Q_PROPERTY macro.
In Qt-documentation
(http://doc.qt.io/qt-4.8/properties.html#requirements-for-declaring-properties),
they tell about the "DISIGNABLE"-attribute:
The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.
Now, i simply built a small test-widget with a label and a Pushbutton. In the code, i have a QString-property "smallText"
.h-file
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
Q_PROPERTY(QString smallText READ smallText WRITE setSmallText NOTIFY smallTextChanged)
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QString smallText() const
{
return m_smallText;
}
public slots:
void setSmallText(QString smallText);
{
if (m_smallText == smallText)
return;
m_smallText = smallText;
emit smallTextChanged(smallText);
}
signals:
void smallTextChanged(QString smallText);
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QString m_smallText;
};
when i click on the Pushbutton, the Property "smallText" is changed, but where can I tell the label to change?
Of course, I could move the definition of "setSmallText" to the *.cpp-file and add
ui->label->setText(smallText);, but is there any possibility to use the the "DESIGNABLE"-attribute?
I unfortunately have to use Qt4.5.2 with Qt-Creator
Thanks for any help:)
Robby
I have a question about the Q_PROPERTY macro.
In Qt-documentation
(http://doc.qt.io/qt-4.8/properties.html#requirements-for-declaring-properties),
they tell about the "DISIGNABLE"-attribute:
The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.
Now, i simply built a small test-widget with a label and a Pushbutton. In the code, i have a QString-property "smallText"
.h-file
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
Q_PROPERTY(QString smallText READ smallText WRITE setSmallText NOTIFY smallTextChanged)
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QString smallText() const
{
return m_smallText;
}
public slots:
void setSmallText(QString smallText);
{
if (m_smallText == smallText)
return;
m_smallText = smallText;
emit smallTextChanged(smallText);
}
signals:
void smallTextChanged(QString smallText);
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QString m_smallText;
};
when i click on the Pushbutton, the Property "smallText" is changed, but where can I tell the label to change?
Of course, I could move the definition of "setSmallText" to the *.cpp-file and add
ui->label->setText(smallText);, but is there any possibility to use the the "DESIGNABLE"-attribute?
I unfortunately have to use Qt4.5.2 with Qt-Creator
Thanks for any help:)
Robby