Results 1 to 3 of 3

Thread: Retrieve QTreeWidgetItem in delegate

  1. #1
    Join Date
    Mar 2011
    Qt products

    Default Retrieve QTreeWidgetItem in delegate

    I have a class that inherits QStyledItemDelegate. I override the following methods:

    Qt Code:
    1. QWidget *createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
    2. void setModelData( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
    3. void setEditorData ( QWidget * editor, const QModelIndex & index ) const;
    To copy to clipboard, switch view to plain text mode 

    Is it possible to retrieve the QTreeWidgetItem on which the user clicked in the createEditor method of the delegate?

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Retrieve QTreeWidgetItem in delegate

    If you pass a pointer to the tree widget to the delegate so that you can retrieve it in createEditor() then you can use QTreeWidget::itemFromIndex().
    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 2 users say thank you to wysota for this useful post:

    Phlucious (3rd June 2016), torres (4th April 2011)

  4. #3
    Join Date
    Jan 2011
    Thanked 4 Times in 2 Posts
    Qt products

    Default Re: Retrieve QTreeWidgetItem in delegate

    Sorry for resurrecting this, but it's a very useful post. How does this work, though, since QTreeWidget::itemFromIndex is protected?

    Added after 22 minutes:

    In the end, I didn't need the item but rather its data. Instead, I called QModelIndex::data() with the appropriate data role and worked with that. That's what QStyledItemDelegate does in the base implementation, by the way. Depending on your use case, that might work for you.
    Last edited by Phlucious; 3rd June 2016 at 20:00.

Similar Threads

  1. Retrieve other windows geometry
    By Talei in forum Newbie
    Replies: 1
    Last Post: 25th January 2011, 23:27
  2. Replies: 5
    Last Post: 23rd September 2010, 13:58
  3. retrieve code from DLL
    By kernel.roy in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2010, 08:03
  4. retrieve code from DLL
    By kernel.roy in forum Newbie
    Replies: 1
    Last Post: 15th September 2010, 06:21
  5. Replies: 2
    Last Post: 24th May 2009, 10:27

Tags for this Thread


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.