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. [Solved] How can i make a Particular Column as Non Editable in QTableView
QtWS25 Last Chance

[Solved] How can i make a Particular Column as Non Editable in QTableView

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 10.2k 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.
  • M Offline
    M Offline
    Macro
    wrote on last edited by
    #1

    I have a QTableView with 4 Rows and 4 columns each representing their data's in it. By default the QTableView is Editable. Now i want to make any Particular Column as non Editable in my QTableView. How can i make a partticular column as a non editable column..?

    Thanks i& Regards...

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Well, you can't if you ask me. I had the same problem with a double click setup on a cell. The solution I did was check the QIndex in the model and when it's the wrong column, don't do anything with it.
      That should do the trick. No idea if there are better ways to do it!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexisdm
        wrote on last edited by
        #3

        You can modify the model so that QAbstractItemModel::flags() doesn't return the flag Qt::ItemIsEditable for all the indexes of the non-editable columns, or if you can't modify the model because, for example, you want the columns to be editable in another view, you can instead use a proxy model and redefine its flags() function.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Macro
          wrote on last edited by
          #4

          Thanks a lot for your replies.. :)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cojack
            wrote on last edited by
            #5

            http://www.qtcentre.org/threads/9020-QTreeView-rows-editable?p=48078#post48078

            Check this, I also see there is a option in QStandardItemModel in method setData in third param to pass the flag as: Qt::DisplayRole, maybe it will prevent editable row, I'm not sure about this.

            http://doc.qt.digia.com/qt/qstandarditemmodel.html#setData

            Regards.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Macro
              wrote on last edited by
              #6

              Yeah i solved it. Thanks all for your suggstions. Here's my Coding.. Here, I had sub classed my Standard items.

              @Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex &index) const
              {
              Qt::ItemFlags flags;

              flags = QAbstractItemModel::flags(index);
              
              if (!(index.column() == 1) && !(index.column() == 3))
              {
                  if(!(index.row()==1) && !(index.row() == 3))
                  {
              
                      flags |=  Qt::ItemIsEditable;
                      return flags;
                  }
              }
              return  QAbstractItemModel::flags(index);
              

              }
              @

              Thanks and Regards....

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                There is also a ready-made "proxy model":http://qt-project.org/wiki/QSortFilterProxyModel_subclass_for_text_alignment_-and_readonly_columns available on the wiki for this.

                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