Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Question about Delegates in QTableView

    General and Desktop
    4
    5
    1290
    Loading More Posts
    • 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
      alizadeh91 last edited by

      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 Reply Quote 0
      • H
        Hostel last edited by

        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 Reply Quote 0
        • G
          giesbert last edited by

          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 Reply Quote 0
          • jazzycamel
            jazzycamel last edited by

            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 Reply Quote 0
            • A
              alizadeh91 last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post