Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Forbid edition for a specified column of a QTreeView... ?
Qt 6.12 LTS is out! See what's new in the release blog

Forbid edition for a specified column of a QTreeView... ?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.8k 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.
  • jerome_isAviableJ Offline
    jerome_isAviableJ Offline
    jerome_isAviable
    wrote on last edited by
    #1

    is it possible with Qt5 ?

    for exemple, i have q QTreeView with 5 columns (from 0 to 4), the last column is hidden... (this.. OK)
    then, i would like the items of columns: [0,1,2] forbid edition but the items of column 3 autorize the edition.

    How to do it (easy) ?

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

      Hi,

      Since you are using a QTreeView you are probably using a custom model then you can reimplement the flags(const QModelIndex &) const method to return the original flags minus Qt::ItemisEditable.

      Hope it helps

      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
      • jerome_isAviableJ Offline
        jerome_isAviableJ Offline
        jerome_isAviable
        wrote on last edited by
        #3

        for one of them i have a model, not for the other one...

        so.. ok... it is really heavy that there is no member function able to do a job easier than this way. Each time i want a little personalization (who is not irrealist personalization), i have to do increase code a lot... and find solution Qt can not provide by these member functions... (sniff)

        ok... it is like that... thanks to help SGaist.

        1 Reply Last reply
        0
        • jerome_isAviableJ Offline
          jerome_isAviableJ Offline
          jerome_isAviable
          wrote on last edited by
          #4

          ok... i have an other idea... because i need to do crafts work and maybe quick more to use code exist allready in my application, i think about use the mouseEvent double click and select condition on columns index i choose for forbid the entry...
          pfff....

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

            The reimplementation of flags is less then 10 lines of code

            @
            Qt::ItemFlags MySuperModel::flags(const QModelIndex & index) const
            {
            if (!index.isValid())
            return Qt::ItemIsEnabled;

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

            }
            }
            @

            Otherwise you can also create a QIdentityProxyModel that does it and insert it between both models and respective views.

            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
            1
            • jerome_isAviableJ Offline
              jerome_isAviableJ Offline
              jerome_isAviable
              wrote on last edited by
              #6

              thanks SGaist i will use this for this one has allready a custom model, this technic seems to be more quick and esay that i thank.
              and I will use event on mouse Release double click for the other one has only view custom class.

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

                I would really advise you to go with one solution instead. In your situation, it seems a proxy model approach would be the best. What's more, you don't even have to write it yourself. "This snippet":/wiki/QSortFilterProxyModel_subclass_for_readonly_columns_columns_with_checkboxes_and_password_columns provides proxy model that can do what you want (and more).

                1 Reply Last reply
                1
                • jerome_isAviableJ Offline
                  jerome_isAviableJ Offline
                  jerome_isAviable
                  wrote on last edited by
                  #8

                  The post is old, but i think this question will be ask many times.

                  By the time, i think that your answer, SGaist and andre are together right.
                  Difficult to do a choice, and that depend of the futur implementation of code.
                  The best is to be able to know to do these two solutions.
                  For my thinking, i think that delegate is good when it is for a simple view without a specific model.
                  thank you.

                  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
                  • Unsolved