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] setItemDelegate does not seem to work
QtWS25 Last Chance

[SOLVED] setItemDelegate does not seem to work

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 6.8k 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.
  • S Offline
    S Offline
    sptrakesh
    wrote on last edited by
    #1

    Hello,

    I am trying to set a delegate on a treeview, however the delegate does not seem to be set (or possibly is being over-written at some other place).

    In my window constructor I have the following

    @ ui->setupUi( this );
    ui->document->setModel( new DocumentModel( this ) );
    ui->document->setItemDelegateForColumn( 2, new ElementValueDelegate( this ) );@

    I set a break point in the delegate createEditor method and it never gets there. I looked at the properties in the UI file and there is no configuration for a delegate. I also tried setItemDelegate for the entire tableview, but still the same behaviour.

    The editTriggers property for the table view in the UI file is set to DoubleClicked and EditKeyPressed. Double clicking cells in the 3rd column, or selecting and hitting return have no effect.

    This is with Qt 4.8.1 on Mac OS X Snow Leopard. What could be wrong?

    Thanks
    Rakesh

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      It's possible that the signature of your createEditor() does not exactly match the virtual function it is supposed to be replacing, e.g. forgot the const qualifier.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sptrakesh
        wrote on last edited by
        #3

        The methods in the delegate header are defined as follows:

        @ QWidget* createEditor( QWidget* parent,
        const QStyleOptionViewItem& option, const QModelIndex& index ) const;

            void setEditorData( QWidget* editor, const QModelIndex& index ) const;
        
            void setModelData( QWidget* editor, QAbstractItemModel* model,
                const QModelIndex& index ) const;@
        

        They seem exactly like the documentation shows. I have not over-ridden the paint method, since I do not think I require custom painting. Could that be the reason?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sptrakesh
          wrote on last edited by
          #4

          I implemented the paint method and just pass through to the QStyledItemDelegate::paint method. This method is indeed being called, but the others still are not firing. So, the delegate is being used, but I must be missing some other setting that would trigger invocation of the createEditor method.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sptrakesh
            wrote on last edited by
            #5

            The source files are at:

            http://kenai.com/projects/mongoviewer/sources/svn/show/desktop/trunk/src/model/tree?rev=69
            http://kenai.com/projects/mongoviewer/sources/svn/content/desktop/trunk/src/model/tree/ElementValueDelegate.h?rev=69
            http://kenai.com/projects/mongoviewer/sources/svn/content/desktop/trunk/src/model/tree/ElementValueDelegate.cpp?rev=69

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              If the delegate is set on the column (or view) and an editor is required then it should be called. The fact that the paint() method is being called is proof that the delegate has been attached.

              Your createEditor() is not being called. Are you getting the default editor, or no editor at all? Is the model returning flags() indicating that the column (or individual item) is editable?

              Are you attaching the delegate to the correct column? Column 2, i.e. the third column, of the model may not be the third visible column in the view if you are hiding or reordering columns.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sptrakesh
                wrote on last edited by
                #7

                Setting the ItemIsEditable flag for the column in the model was the missing step. Thanks for pointing it out.

                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