ui->treeWidget->setColumnCount(1); //設置列數 ui->treeWidget->setHeaderLabel(tr("構件選擇")); //設置頭的標題 ui->treeWidget->setHeaderHidden(true);//隱藏表頭 QPalette p(ui->treeWidget->palette());//設置背景色 p.setColor(QPalette::Base, QColor("#ced9e6")); ui->treeWidget->setPalette(p); QTreeWidgetItem *imageItem1 = new QTreeWidgetItem(ui->treeWidget,QStringList(QString("主構件"))); imageItem1->setBackgroundColor(0,QColor("#e5ebf4"));//設置背景顏色 QTreeWidgetItem *imageItem1_1 = new QTreeWidgetItem(imageItem1,QStringList(QString("鋼柱"))); //子節點1 QTreeWidgetItem *imageItem1_2 = new QTreeWidgetItem(imageItem1,QStringList(QString("鋼樑"))); //子節點2 QTreeWidgetItem *imageItem1_3 = new QTreeWidgetItem(imageItem1,QStringList(QString("吊車梁"))); //子節點3 QTreeWidgetItem *imageItem1_4 = new QTreeWidgetItem(imageItem1,QStringList(QString("衍架"))); //子節點4 QTreeWidgetItem *imageItem1_5 = new QTreeWidgetItem(imageItem1,QStringList(QString("格構柱"))); //子節點5 imageItem1_1->setForeground(0,QBrush(QColor("#546892")));//設置文字顏色 imageItem1_2->setForeground(0,QBrush(QColor("#546892"))); imageItem1_3->setForeground(0,QBrush(QColor("#546892"))); imageItem1_4->setForeground(0,QBrush(QColor("#546892"))); imageItem1_5->setForeground(0,QBrush(QColor("#546892"))); imageItem1_1->setIcon(0,QIcon(":/new/prefix1/img/images/1.png"));//設置圖標 imageItem1_2->setIcon(0,QIcon(":/new/prefix1/img/images/1.png")); imageItem1_3->setIcon(0,QIcon(":/new/prefix1/img/images/1.png")); imageItem1_4->setIcon(0,QIcon(":/new/prefix1/img/images/1.png")); imageItem1_5->setIcon(0,QIcon(":/new/prefix1/img/images/1.png")); imageItem1->addChild(imageItem1_1); //添加子節點 imageItem1->addChild(imageItem1_2); imageItem1->addChild(imageItem1_3); imageItem1->addChild(imageItem1_4); imageItem1->addChild(imageItem1_5); ui->treeWidget->expandAll(); //結點所有展開
ui->treeWidget->setRootIsDecorated(false);//隱藏根節點前面的小箭頭 // // // // imageItem1->setIcon(0,QIcon(":/new/prefix1/img/images/jianhao.png"));//設置圖標