PDA

View Full Version : QTreeWidget edit



baray98
7th November 2007, 00:00
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



for (int i = 0 ; i < keyList.count(); i++) // keylist is declared as QStringList
{
QTreeWidgetItem *headItem = new QTreeWidgetItem(treeSensor);
headItem->setText(0, QString("HD%1").arg(keyList.value(i)));
headItem->setCheckState(0, Qt::Unchecked);

for (int j = 0 ; j < 2; j++)
{
QTreeWidgetItem *axItem = new QTreeWidgetItem(headItem);
axItem->setText(0, QString("A%1").arg(j+1));
axItem->setCheckState(0, Qt::Unchecked);
strColor = color(colorNames); // generates a color name known to Qt
axItem->setData(1,Qt::DecorationRole,QColor(strColor));
axItem->setData(1,Qt::DisplayRole,strColor);
axItem->setFlags(axItem->flags()|Qt::ItemIsEditable); //this did not work

QTreeWidgetItem *radItem = new QTreeWidgetItem(headItem);
radItem->setText(0, QString("R%1").arg(j+1));
radItem->setCheckState(0, Qt::Unchecked);
strColor = color(colorNames);
radItem->setData(1,Qt::DecorationRole,QColor(strColor));
radItem->setData(1,Qt::DisplayRole,strColor);

QTreeWidgetItem *cirItem = new QTreeWidgetItem(headItem);
cirItem->setText(0, QString("C%1").arg(j+1));
cirItem->setCheckState(0, Qt::Unchecked);
strColor = color(colorNames);
cirItem->setData(1,Qt::DecorationRole,QColor(strColor));
cirItem->setData(1,Qt::DisplayRole,strColor);
}
QTreeWidgetItem *eddyItem = new QTreeWidgetItem(headItem);
eddyItem->setText(0, QString("ED"));
eddyItem->setCheckState(0, Qt::Unchecked);
strColor = color(colorNames);
eddyItem->setData(1,Qt::DecorationRole,QColor(strColor));
eddyItem->setData(1,Qt::DisplayRole,strColor);
}


help ,

baray98

wysota
7th November 2007, 05:13
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.

baray98
7th November 2007, 15:44
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



//creates Color Editor
QItemEditorFactory *factory = new QItemEditorFactory;
QItemEditorCreatorBase *colorListCreator =
new QStandardItemEditorCreator<ColorEditor>();
factory->registerEditor(QVariant::Color, colorListCreator);
QItemEditorFactory::setDefaultFactory(factory);


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