Text delegate updates in value, but Gauge delegate does not update value
-
Hello, in following, text delegate updates in UI, but replacing it with gauge does not update the UI. There is nothing. I have no clue what went wrong.
GridView { width: parent.width; height: parent.height cellHeight: 250 cellWidth: 250 model: amodel delegate: Component { id: redSquare Rectangle { color: "steelblue" width: 240 height: 240 Text { text: value anchors.centerIn: parent.Center font.pointSize: 50 } } } }GridView { width: parent.width; height: parent.height cellHeight: 250 cellWidth: 250 model: amodel delegate: Component { id: redSquare Gauge { value: value minimumValue: 0 maximumValue: 100 } } }The model is QAbstractItemModel.
#include <QAbstractListModel> #include <QStringList> #include <QTimer> class Animal { public: Animal(const QString &type, const QString &size, const int &value); QString type() const; QString size() const; int value() const; QString m_type; QString m_size; int m_value; }; class AnimalModel : public QAbstractListModel { Q_OBJECT public: enum AnimalRoles { TypeRole = Qt::UserRole + 1, SizeRole, ValueRole }; explicit AnimalModel(QObject *parent = nullptr); void addAnimal(const Animal &animal); int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); protected: QHash<int, QByteArray> roleNames() const; private slots: void update(); private: QList<Animal> m_animals; QTimer* m_timer; }; -
Hello, in following, text delegate updates in UI, but replacing it with gauge does not update the UI. There is nothing. I have no clue what went wrong.
GridView { width: parent.width; height: parent.height cellHeight: 250 cellWidth: 250 model: amodel delegate: Component { id: redSquare Rectangle { color: "steelblue" width: 240 height: 240 Text { text: value anchors.centerIn: parent.Center font.pointSize: 50 } } } }GridView { width: parent.width; height: parent.height cellHeight: 250 cellWidth: 250 model: amodel delegate: Component { id: redSquare Gauge { value: value minimumValue: 0 maximumValue: 100 } } }The model is QAbstractItemModel.
#include <QAbstractListModel> #include <QStringList> #include <QTimer> class Animal { public: Animal(const QString &type, const QString &size, const int &value); QString type() const; QString size() const; int value() const; QString m_type; QString m_size; int m_value; }; class AnimalModel : public QAbstractListModel { Q_OBJECT public: enum AnimalRoles { TypeRole = Qt::UserRole + 1, SizeRole, ValueRole }; explicit AnimalModel(QObject *parent = nullptr); void addAnimal(const Animal &animal); int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); protected: QHash<int, QByteArray> roleNames() const; private slots: void update(); private: QList<Animal> m_animals; QTimer* m_timer; };Hi,
the problem is here :
@milan said in Text delegate updates in value, but Gauge delegate does not update value:Gauge {
value: value
minimumValue: 0
maximumValue: 100
}that Gauge has a property named
value.
value: value
now binds the Gauge-Value to itself. You'll have to prepent the Item id.Gauge { value: parent.value //parent is example, no idea where value actually comes from minimumValue: 0 maximumValue: 100 }

