开发者

Add textEdit as child to row

开发者 https://www.devze.com 2023-03-21 16:29 出处:网络
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 l

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 :

Add textEdit as child to row

0

精彩评论

暂无评论...
验证码 换一张
取 消