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. Question about Delegates in QTableView

Question about Delegates in QTableView

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

    Hi guys :)
    I have delegate from QStyledItemDelegate. In my TableView i want to make a specified cell read only. I want to do it in delegate. How can i do that?

    Second Question: How can i get editor of a specified cell in delegate class?

    Thanks :)

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      I don't know if this will work but you can try reimplement a createEditor. Something like this:
      @
      QWidget * MyDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
      {
      QWidget* editor = QStyledItemDelegate::createEditor( parent, option, index );
      // cast or something and set readOnly?
      return editor;
      }
      @

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Hi,

        regarding your two questions:

        1.) makes no sense in the delegate. The delegate comes into the game for handling editors and painting, not for data access. If you have to make changes on the data level, make it in a proxy model.

        2.) The delegate creates the editors, where do you need to get an editor for a specific cell in the delegate?

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • jazzycamelJ Offline
          jazzycamelJ Offline
          jazzycamel
          wrote on last edited by
          #4

          If you want the a particular cell to be read only (i.e. not editable) then the model its associated with should return the appropriate "ItemFlags":http://doc.qt.digia.com/4.7-snapshot/qt.html#ItemFlag-enum for that index from its "flags":http://doc.qt.digia.com/4.7-snapshot/qabstractitemmodel.html#flags method (probably just ItemIsSelectable and ItemIsEnabled). This should not be done in a delegate, its not what they're for.

          For the avoidance of doubt:

          1. All my code samples (C++ or Python) are tested before posting
          2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
          1 Reply Last reply
          0
          • A Offline
            A Offline
            alizadeh91
            wrote on last edited by
            #5

            Ok thanks :) i got it. i'll do it in my proxy model :)

            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