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. QTableView make one colmum editable

QTableView make one colmum editable

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.9k Views 2 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    I found a lot in the internet about it, but I have one problem.
    I made a QFilterSortProxyModel and want overwrite the flags.
    Is there a more easy solution for this common task ?

    class SpecialProxy: public QSortFilterProxyModel
    {public:
        SpecialProxy(QObject* o):QSortFilterProxyModel(o) {}
        virtual Qt::ItemFlags flags(const QModelIndex& index) const override
            {
               Qt::ItemFlags result = this->sourceModel()->flags(index);
               if (index.column() == 3) 
               {
                   result |= Qt::ItemIsEditable;
               }
               return result;
            }
    

    Must I enable all edit flags in the QTableView and disable the editable-flag in proxy model ? How get I the default flags ?
    The sourcemodel seen to have not the correct flags! If I use the code above no selection of the whole table works (nor editing works). Why that ?

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

      Just call the base class version

      class SpecialProxy: public QSortFilterProxyModel
      {public:
          SpecialProxy(QObject* o):QSortFilterProxyModel(o) {}
          virtual Qt::ItemFlags flags(const QModelIndex& index) const override
              {
                 Qt::ItemFlags result = QSortFilterProxyModel::flags(index);
                 if (index.column() == 3) 
                 
                     result |= Qt::ItemIsEditable;
                 
      else
      result &= ~Qt::ItemIsEditable; // All other columns not editable
                 return result;
              }
      

      "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

      Andy314A 1 Reply Last reply
      1
      • VRoninV VRonin

        Just call the base class version

        class SpecialProxy: public QSortFilterProxyModel
        {public:
            SpecialProxy(QObject* o):QSortFilterProxyModel(o) {}
            virtual Qt::ItemFlags flags(const QModelIndex& index) const override
                {
                   Qt::ItemFlags result = QSortFilterProxyModel::flags(index);
                   if (index.column() == 3) 
                   
                       result |= Qt::ItemIsEditable;
                   
        else
        result &= ~Qt::ItemIsEditable; // All other columns not editable
                   return result;
                }
        
        Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by
        #3

        Hello @VRonin,
        ok thank you this works.

        But the changing in the database does not. After refresh I get once a again the same data.

            TPModel = new QSqlTableModel (this);
            TPModel->setTable("qryTransportGUI");
            SpecialProxy *Proxy = new SpecialProxy(this);
            Proxy->setSourceModel(TPModel);
            ui->TPView->setModel(Proxy);
        

        The edit action does not write in the queried data !

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

          Hi,

          Did you check the edit strategy of your model ?

          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

          • Login

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