Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Text delegate updates in value, but Gauge delegate does not update value

Text delegate updates in value, but Gauge delegate does not update value

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 655 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    milan
    wrote on last edited by milan
    #1

    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;
    };
    
    
    
    
    J.HilkJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      milan
      wrote on last edited by
      #2

      In gauge delegate, I can see only this.
      0_1539930825357_69909d02-5d41-4df4-9cc9-61ba2fee968b-image.png

      In Text delegates, I can see the changing values
      0_1539930975760_6ffc45dc-d4f6-4e1b-a620-0a122414c92e-image.png

      1 Reply Last reply
      0
      • M Offline
        M Offline
        milan
        wrote on last edited by
        #3

        Also, I found the progressbar delegate also fails.

        1 Reply Last reply
        0
        • M milan

          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;
          };
          
          
          
          
          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          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
                      }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          2

          • Login

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