Results 1 to 2 of 2

Thread: Problem with Delegates in QTreeWidget

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Question Problem with Delegates in QTreeWidget

    Hi,

    I am trying to figure out how QT delegates are supposed to work so I put a Delegate into QTreeWidget. I used default SpinBoxDelegate for a simple test below.

    Qt Code:
    1. QTreeWidget *view = new QTreeWidget();
    2.  
    3.  
    4. view->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
    5. view->setSelectionBehavior(QAbstractItemView::SelectRows);
    6.  
    7. SpinBoxDelegate *delegate = new SpinBoxDelegate ();
    8. view->setItemDelegate(delegate);
    9.  
    10. for (int row = 0; row < 20; ++row) {
    11. QTreeWidgetItem *item0 = new QTreeWidgetItem(view);
    12. item0->setText(0, QString("Test") + QString::number(row));
    13.  
    14. view->addTopLevelItem(item0);
    15. }
    16.  
    17. view->expandAll();
    18. view->show();
    To copy to clipboard, switch view to plain text mode 

    In a result SpinBoxDelegate::createEditor never gets called.
    What could be wrong with my code?
    Last edited by DeRatizator; 1st October 2010 at 11:19.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with Delegates in QTreeWidget

    You have to set the item flag Qt::ItemIsEditable.

    Moving to newbie.

Similar Threads

  1. Models and Delegates
    By bgeller in forum Newbie
    Replies: 13
    Last Post: 4th March 2010, 04:46
  2. Trying to use delegates...
    By foahchon in forum Qt Programming
    Replies: 7
    Last Post: 28th August 2009, 07:17
  3. Help plz! I’m stuck with these delegates
    By codeaddict in forum Qt Programming
    Replies: 7
    Last Post: 19th August 2008, 21:33
  4. delegates
    By hgedek in forum Newbie
    Replies: 3
    Last Post: 24th October 2007, 19:00
  5. Delegates and Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2006, 19:47

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.