Results 1 to 3 of 3

Thread: delegate doesn't get called when using QTreeWidget but works find with QTableWidget

  1. #1
    Join Date
    Mar 2011
    Posts
    15
    Thanks
    4
    Qt products
    Qt4

    Default delegate doesn't get called when using QTreeWidget but works find with QTableWidget

    The delegate function: createEditor(...) doesn't get called when using a QTreeWidget.
    Double clicking on an item in the tree widget has no effect.
    Does somebody see what I'm doing wrong?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc,argv);
    4. QTreeWidget* tree = new QTreeWidget;
    5.  
    6. tree->setItemDelegate(new MyDelegate);
    7. tree->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
    8.  
    9. tree->setColumnCount(1);
    10.  
    11. QTreeWidgetItem *item01 = new QTreeWidgetItem(tree);
    12. item01->setData(0, Qt::EditRole /*Qt::DisplayRole*/, QVariant("item01"));
    13. item01->setText(0, "item01");
    14. tree->addTopLevelItem(item01);
    15.  
    16. tree->show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    The implementation of the delegate class doesn't matter. The create editor method doesn't get called. If I use a QTableWidget instead of a QTreeWidget, it works fine. The class declaration of the delegate looks like this:
    Qt Code:
    1. #include <QStyledItemDelegate>
    2.  
    3. class MyDelegate : public QStyledItemDelegate
    4. {
    5. Q_OBJECT
    6. public:
    7. MyDelegate(QObject *parent = 0);
    8. ~MyDelegate() {}
    9.  
    10. void paint(QPainter *painter, const QStyleOptionViewItem &option,
    11. const QModelIndex &index) const;
    12. QSize sizeHint(const QStyleOptionViewItem &option,
    13. const QModelIndex &index) const;
    14. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    15. const QModelIndex &index) const;
    16. void setEditorData(QWidget *editor, const QModelIndex &index) const;
    17. void setModelData(QWidget *editor, QAbstractItemModel *model,
    18. const QModelIndex &index) const;
    19.  
    20. private slots:
    21. void commitAndCloseEditor();
    22. };
    To copy to clipboard, switch view to plain text mode 

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: delegate doesn't get called when using QTreeWidget but works find with QTableWidg

    Are the items flagged as editable?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    torres (21st March 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    15
    Thanks
    4
    Qt products
    Qt4

    Default Re: delegate doesn't get called when using QTreeWidget but works find with QTableWidg

    No, that solved the problem:
    Qt Code:
    1. item01->setFlags(item01->flags() | Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 

    Thanks!

Similar Threads

  1. delegate sizeHint not getting called
    By skuda in forum Qt Programming
    Replies: 9
    Last Post: 16th March 2011, 15:09
  2. createEditor() is not called in custom delegate
    By landstreicher in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2010, 03:41
  3. Slot doesn't get called
    By waynew in forum Qt Programming
    Replies: 7
    Last Post: 18th April 2010, 13:34
  4. How come this slot doesn't get called every second?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 23:41
  5. QString - no member function called 'find'
    By pitterb in forum Newbie
    Replies: 1
    Last Post: 13th January 2009, 11:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.