Add textEdit as child to row
I want to add TextEdit as a child to QTreeWidget when chciking each row of treewidget. Can someone 开发者_如何转开发help by giving clue.
You can use the setItemWidget() function to set any widget you like to be at a given position in a treeview. An example might look like :
#include <QApplication>
#include <QTreeWidget>
#include <QLineEdit>
int main(int argc, char** argv)
{
QApplication a(argc, argv);
QTreeWidget *tw = new QTreeWidget;
// Add some sample items to the QTreeWidget
for(int i=0; i<10; i++)
{
QStringList strings;
strings << QString("Item %1").arg(i+1);
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
tw->addTopLevelItem(parent);
// Add the child TreeWidgetItem one step down in the tree
QTreeWidgetItem *child = new QTreeWidgetItem;
parent->addChild(child);
// Set the widget for the child item to be a QLineEdit for column zero.
tw->setItemWidget(child, 0, new QLineEdit(tw));
}
tw->show();
return a.exec();
}
This looks like this :
精彩评论