Qt Forum

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

    [SOLVED] setItemDelegate does not seem to work

    General and Desktop
    2
    7
    6209
    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.
    • S
      sptrakesh last edited by

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

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

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

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

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

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

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

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