QT中tableWidget常用设置,设置选中单击选中一行、设置内容不可编辑

QT中tableWidget常用设置,设置选中单击选中一行、设置内容不可编辑

QTableWidgetItem *nickItem = new QTableWidgetItem(nick); QTableWidgetItem *hostNameItem = new QTableWidgetItem(hostName); QTableWidgetItem *hostIpItem = new QTableWidgetItem(hostIp); this->ui->friendList->insertRow(0); this->ui->friendList->setItem(0, 0, nickItem); this->ui->friendList->setItem(0, 1, hostNameItem); this->ui->friendList->setItem(0, 2, hostIpItem); this->ui->friendList->setSelectionBehavior(QAbstractItemView::SelectRows); //单击选择一行 this->ui->friendList->setSelectionMode(QAbstractItemView::SingleSelection); //设置只能选择一行,不能多行选中 this->ui->friendList->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置每行内容不可更改 this->ui->friendList->setAlternatingRowColors(true); //设置隔一行变一颜色,即:一灰一白  

你可能感兴趣的:(QT,aka笔记,qt)