table_widget->setGeometry(14,58,738,381);
table_widget->setColumnCount(4);
table_widget->setColumnWidth(0,44);//设置列宽
table_widget->setColumnWidth(1,44);//设置列宽
table_widget->setColumnWidth(2,100);//设置列宽
table_widget->setColumnWidth(3,102);//设置列宽
table_widget->horizontalHeader()->setDefaultSectionSize(150);
table_widget->horizontalHeader()->setClickable(false);
QStringList header;
header<<tr("name")<<tr("last modify time")<<tr ("type")<<tr("size");
table_widget->setHorizontalHeaderLabel
QFont font
font.setBold(true);
table_widget->horizontalHeader()->setFont(font);
table_widget->horizontalHeader()->setStretchLastSection(true);
table_widget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table_widget->verticalHeader()->setDefaultSectionSize(10);
table_widget->setFrameShape(QFrame::NoFrame);
table_widget->setShowGrid(false);
table_widget->verticalHeader()->setVisible(false);
table_widget->setSelectionMode(QAbstractItemView::ExtendedSelection);
table_widget->setSelectionBehavior(QAbstractItemView::SelectRows);
table_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
table_widget->horizontalHeader()->resizeSection(0,150);
table_widget->horizontalHeader()->setFixedHeight(25);
table_widget->setStyleSheet("selection-background-color:lightblue;");
table_widget->horizontalHeader()->setStyleSheet("QHeaderView::section{background:skyblue;}");
//设置水平、垂直滚动条样式
table_widget->horizontalScrollBar()->setStyleSheet("QScrollBar{background:transparent; height:10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
"QScrollBar::add-line{background:transparent;}");
table_widget->verticalScrollBar()->setStyleSheet("QScrollBar{background:transparent; width: 10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
void UsbCheck::changeTest(int row, int col)
{
if(ui->tableWidget->item(row, col)->checkState()==Qt::Checked)
{
integerVector.append(row);
}
}
void UsbCheck::deleteRow()
{
cout<<integerVector.size()<<endl; for(int i=0;i<</SPAN>integerVector.size();i++)
{
cout<<integerVector[i]<<endl;
ui->tableWidget->removeRow(integerVector[i]);
}
integerVector.clear();
}
//插入复选框控件
auto rowID = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(rowID+1);//新增行
QTableWidgetItem *checkbox = new QTableWidgetItem();
checkbox->setCheckState(Qt::Unchecked);
ui->tableWidget->setItem(rowID, 0, checkbox); //插入复选框
ui->tableWidget->setItem(rowID, 1, new QTableWidgetItem(QString::number(rowID)));
ui->tableWidget->setItem(rowID, 2, newQTableWidgetItem(QString::fromStdWString(usbinfo[recordNo].Devicetype)));