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. Table view UI update
Forum Updated to NodeBB v4.3 + New Features

Table view UI update

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 546 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.
  • ashajgA Offline
    ashajgA Offline
    ashajg
    wrote on last edited by
    #1

    Hi guys

    I am using Table view.. and trying to update my table view..

    TableView {
    model: TableModel {}
    }
    
    
    **main.cpp**
    qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
    
    
    **TableModel.h**
    QVector<QVector<QString>> m_Model;
    
    
    **TableModel.cpp**
    
    bool TableModel::setData(const QModelIndex &indexPos, const QVariant &value, int role)
    {
        if(data(indexPos, role) == value)
            return false;
    
        QString key = m_Model.at(indexPos.row()).at(indexPos.column()-1);
        qDebug() << "KEY:" << key;
        m_Model.replace(indexPos.row(),{key, value});
        qDebug() << "Model Data Changed!!!" << m_Model;
        QModelIndex start = index(1,0);
        emit dataChanged(start, indexPos, {role});
        return true;
    }
    
    void changeModel() {
           setData(index(1,1), "abc");
    }
    

    But my UI is not getting updated
    How can I solve this issue?

    Thanks!!!

    VRoninV 1 Reply Last reply
    0
    • ashajgA ashajg

      Hi guys

      I am using Table view.. and trying to update my table view..

      TableView {
      model: TableModel {}
      }
      
      
      **main.cpp**
      qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
      
      
      **TableModel.h**
      QVector<QVector<QString>> m_Model;
      
      
      **TableModel.cpp**
      
      bool TableModel::setData(const QModelIndex &indexPos, const QVariant &value, int role)
      {
          if(data(indexPos, role) == value)
              return false;
      
          QString key = m_Model.at(indexPos.row()).at(indexPos.column()-1);
          qDebug() << "KEY:" << key;
          m_Model.replace(indexPos.row(),{key, value});
          qDebug() << "Model Data Changed!!!" << m_Model;
          QModelIndex start = index(1,0);
          emit dataChanged(start, indexPos, {role});
          return true;
      }
      
      void changeModel() {
             setData(index(1,1), "abc");
      }
      

      But my UI is not getting updated
      How can I solve this issue?

      Thanks!!!

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @ashajg said in Table view UI update:

      But my UI is not getting updated

      does this mean that it still shows the old values or just displays nothing at all?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • ashajgA Offline
        ashajgA Offline
        ashajg
        wrote on last edited by
        #3

        Hi @VRonin

        Thanks for reply!!!

        Its Still Showing same values..

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          can you try changing emit dataChanged(start, indexPos, {role}); to emit dataChanged(indexPos, indexPos);?

          P.S.
          Your setData doesn't seem to manage roles correctly but this is another, separate, problem

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • ashajgA Offline
            ashajgA Offline
            ashajg
            wrote on last edited by
            #5

            ok I ll try that..

            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