Results 1 to 3 of 3

Thread: QTreeWidget edit

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget edit

    I am trying to make the item in my QTreeWidget editable and I am not successful

    heres the code making my tree, please help me point out what should i do to make it editable

    Qt Code:
    1. for (int i = 0 ; i < keyList.count(); i++) // keylist is declared as QStringList
    2. {
    3. QTreeWidgetItem *headItem = new QTreeWidgetItem(treeSensor);
    4. headItem->setText(0, QString("HD%1").arg(keyList.value(i)));
    5. headItem->setCheckState(0, Qt::Unchecked);
    6.  
    7. for (int j = 0 ; j < 2; j++)
    8. {
    9. QTreeWidgetItem *axItem = new QTreeWidgetItem(headItem);
    10. axItem->setText(0, QString("A%1").arg(j+1));
    11. axItem->setCheckState(0, Qt::Unchecked);
    12. strColor = color(colorNames); // generates a color name known to Qt
    13. axItem->setData(1,Qt::DecorationRole,QColor(strColor));
    14. axItem->setData(1,Qt::DisplayRole,strColor);
    15. axItem->setFlags(axItem->flags()|Qt::ItemIsEditable); //this did not work
    16.  
    17. QTreeWidgetItem *radItem = new QTreeWidgetItem(headItem);
    18. radItem->setText(0, QString("R%1").arg(j+1));
    19. radItem->setCheckState(0, Qt::Unchecked);
    20. strColor = color(colorNames);
    21. radItem->setData(1,Qt::DecorationRole,QColor(strColor));
    22. radItem->setData(1,Qt::DisplayRole,strColor);
    23.  
    24. QTreeWidgetItem *cirItem = new QTreeWidgetItem(headItem);
    25. cirItem->setText(0, QString("C%1").arg(j+1));
    26. cirItem->setCheckState(0, Qt::Unchecked);
    27. strColor = color(colorNames);
    28. cirItem->setData(1,Qt::DecorationRole,QColor(strColor));
    29. cirItem->setData(1,Qt::DisplayRole,strColor);
    30. }
    31. QTreeWidgetItem *eddyItem = new QTreeWidgetItem(headItem);
    32. eddyItem->setText(0, QString("ED"));
    33. eddyItem->setCheckState(0, Qt::Unchecked);
    34. strColor = color(colorNames);
    35. eddyItem->setData(1,Qt::DecorationRole,QColor(strColor));
    36. eddyItem->setData(1,Qt::DisplayRole,strColor);
    37. }
    To copy to clipboard, switch view to plain text mode 

    help ,

    baray98

  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: QTreeWidget edit

    I assume that you mean that the user should be able to operate the checkbox of the item, correct? If so, you need to set the ItemIsUserCheckable flag and not ItemIsEditable flag on the item.

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget edit

    No, what i meant is that i want my user to be able to change color column (which is the Qt::decorationRole of the second column) i have color editor assigned to this by using the following

    Qt Code:
    1. //creates Color Editor
    2. QItemEditorCreatorBase *colorListCreator =
    3. new QStandardItemEditorCreator<ColorEditor>();
    4. factory->registerEditor(QVariant::Color, colorListCreator);
    5. QItemEditorFactory::setDefaultFactory(factory);
    To copy to clipboard, switch view to plain text mode 

    it seems that i cannot get my ColorEditor to popup , by the way my coloreditor is a QComboBox populated with colors known to Qt.

    baray98

Similar Threads

  1. Line Edit Controll problem
    By mansoorulhaq in forum Qt Programming
    Replies: 5
    Last Post: 31st October 2007, 08:33
  2. QTreeWidget click
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2007, 16:47
  3. Having trouble clearing a QTreeWidget.
    By Nyphel in forum Qt Programming
    Replies: 28
    Last Post: 10th October 2007, 15:33
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.