• 7-18


    Qt 树形结构

    #include "widget.h"
    #include "ui_widget.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);

    QTreeWidget* tree = new QTreeWidget(this);
    tree->setColumnCount(1); //set the number of the colume
    tree->setHeaderLabel(tr("relation net"));
    tree->show();
    //set the widgetitem
    QTreeWidgetItem *item1 = new QTreeWidgetItem(tree,QStringList(QString("friend")));
    QTreeWidgetItem* item1_1 = new QTreeWidgetItem(item1);
    item1_1->setText(0,"jim");

    QTreeWidgetItem *item2 = new QTreeWidgetItem(tree,QStringList(QString("parents")));
    // item2->setText(1,"parents");
    QTreeWidgetItem* item2_2 = new QTreeWidgetItem(item2);
    item2_2->setText(0,"mom");

    tree->expandAll();
    // QTreeWidgetItem *imageItem1_1 = new QTreeWidgetItem(imageItem1,QStringList(QString("Band1"))); //子节点1
    // imageItem1->addChild(imageItem1_1); //添加子节点

    // QTreeWidgetItem *imageItem2 = new QTreeWidgetItem(ui->treeWidget,QStringList(QString("图像2")));
    // QTreeWidgetItem *imageItem2_1 = new QTreeWidgetItem(imageItem2,QStringList(QString("Band1"))); //子节点1
    // QTreeWidgetItem *imageItem2_2 = new QTreeWidgetItem(imageItem2,QStringList(QString("Band2"))); //子节点2
    // imageItem2->addChild(imageItem2_1); //添加子节点
    // imageItem2->addChild(imageItem2_2);

    // ui->treeWidget->expandAll();
    }

    Widget::~Widget()
    {
    delete ui;
    }

  • 相关阅读:
    Linux strace命令
    Xilinx实习一年总结
    Red Hat Linux 挂载外部资源
    4.6、Libgdx线程介绍
    Xshell中文乱码怎么处理?
    C++之指针指向二维数组
    POJ 2996 Help Me with the Game
    UVa 10377
    你们都满足下面的工作考核吗
    使用Python编写简单网络爬虫抓取视频下载资源
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9327775.html
Copyright © 2020-2023  润新知