Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [RESOLVE] Dynamic Property in custom widget plugin for designer (Q_PROPERTY)
QtWS25 Last Chance

[RESOLVE] Dynamic Property in custom widget plugin for designer (Q_PROPERTY)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    trilla
    wrote on last edited by
    #1

    I decided to create a custom widget for the qt-designer.
    The widget itself I made using the qt-designer, then as described here (http://qt-project.org/doc/qt-5.0/qtdesigner/customwidgetplugin.html) I made a plugin and it worked. Further wanted to add a custom widget properties in the property editor in the designer. To do this, I found only one solution:

    @
    // custom_widget.h

    #include <QWidget>
    #include <QString>

    namespace Ui {
    class Form;
    }

    class CustomWidget : public QWidget {
    Q_OBJECT
    Q_PROPERTY(QString text READ getUiTextLabel WRITE setUiTextLabel)

    public:
    explicit CustomWidget(QWidget *parent = 0)
    ~CustomWidget();

    QString getUiTextLabel() const;
    void setUiTextLabel(const QString &text);

    private:
    Ui::Form *ui; // ui generated from uic, and have just QLabel *label
    };

    // custom_widget.cpp

    #include "custom_widget.h"
    #include "ui_form.h"

    CustomWidget::CustomWidget(QWidget *parent)
    : QWidget(parent),
    ui(new Ui::Form) {
    ui->setupUi(this);
    }

    QString CustomWidget::getUiTextLabel() const {
    return ui->label->text();
    }

    void CustomWidget::setUiTextLabel(const QString &text) {
    ui->label->setText(text);
    }

    CustomWidget::~CustomWidget() {
    delete ui;
    }
    @

    May be for this one has a simple solution, without duplicating code?
    And why can't use?
    @
    Q_PROPERTY(QString text READ ui->label->text WRITE ui->label->setText)
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      This is currently the correct and simple solution.

      Have a look at "Q_PROPERTY's documentation":http://qt-project.org/doc/qt-5/qobject.html#Q_PROPERTY to see how it works

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        trilla
        wrote on last edited by
        #3

        Thank you SGaist :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved