QTreeWidget控件单击item



  •     觉得这个控件很适合写简单的工控采集设备信息软件。所以就发出来大家参考参考。
        我们公司是硬件公司,卖出的设备给客户,客户要一个能单点查询设备的状态信息。设备是485的通讯模块,然后转网口到局域网。
    

    0_1452836769486_QQ图片20160115134542.png
    以下是代码,写的很都比,其实可以用switch语句的,但是。。。懒
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <qDebug>

    MainWindow::MainWindow(QWidget parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ui->treeWidget->expandAll();
    ui->label->hide();
    ui->label_2->hide();
    connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem
    ,int)),
    this,SLOT(checkself(QTreeWidgetItem*,int))); // QTreeWidgetItem* 指针
    }

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

    void MainWindow::checkself(QTreeWidgetItem *item ,int count)
    {
    if(item->text(count) != QString::fromUtf8(" 办公综合大楼A区域") &&
    item->text(count) != QString::fromUtf8(" 办公综合大楼B区域") &&
    item->text(count) != QString::fromUtf8(" 办公综合大楼C区域") &&
    item->text(count) != QString::fromUtf8(" 办公综合大楼D区域"))
    {
    ui->label->show();
    ui->label_2->show();
    }
    if(item->text(count) == QString::fromUtf8(" 办公综合大楼A区域") ||
    item->text(count) == QString::fromUtf8(" 办公综合大楼B区域") ||
    item->text(count) == QString::fromUtf8(" 办公综合大楼C区域") ||
    item->text(count) == QString::fromUtf8(" 办公综合大楼D区域"))
    {
    ui->label->hide();
    ui->label_2->hide();
    }
    if(item->text(count) == "A-1")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "A-2")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "A-3")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "A-4")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "A-5")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "B-1")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "B-2")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "C-1")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "C-2")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "C-3")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "C-4")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "C-5")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "D-1")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    if(item->text(count) == "D-2")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/4.png)");
    }
    if(item->text(count) == "D-3")
    {
    ui->label_2->setStyleSheet("border-image: url(:/images/image/5.png)");
    }
    }


 

走马观花

最近的回复

关注我们

微博
QQ群











召唤伊斯特瓦尔