Добавить textEdit как дочерний элемент в строку - PullRequest
0 голосов
/ 18 июля 2011

Я хочу добавить TextEdit как дочерний элемент в QTreeWidget при выборе каждой строки treewidget. Может ли кто-нибудь помочь, дав подсказку.

1 Ответ

2 голосов
/ 18 июля 2011

Вы можете использовать функцию setItemWidget (), чтобы установить любой виджет, который вам нравится, в заданной позиции в виде дерева.Пример может выглядеть так:

#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();
}

Это выглядит так:

Screenshot of TreeWidget

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...