我需要创建一个这样的表。当我选中标题中的复选框时,将自动检查同一列中的所有复选框。如何在标题中创建复选框,如何为该复选框设置信号槽?
这是我的旧代码:
ui.table->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui.table->verticalHeader()->hide();
ui.table->setRowCount(8);
ui.table->setColumnCount(3);
ui.table->setHorizontalHeaderLabels(QStringList() << tr(" ") << tr("Interger") << tr("String"));
for (int i = 0; tableindb.size() > i; i++){
myconstruct ptv = tableindb.value(i);
QTableWidgetItem *itemCheckbox = new QTableWidgetItem(" ");
itemCheckbox->setCheckState(Qt::Unchecked);
ui.table->setItem(i, 0, itemCheckbox);
itemCheckbox->setData(Qt::ItemDataRole::UserRole, ptv.usercheck);
QTableWidgetItem *itemNumber = new QTableWidgetItem("Integer");
itemNumber->setData(Qt::ItemDataRole::DisplayRole, ptv.usernumber);
ui.table->setItem(i, 1, itemNumber);
QTableWidgetItem *itemName = new QTableWidgetItem("String");
itemName->setData(Qt::ItemDataRole::DisplayRole, ptv.username);
ui.table->setItem(i, 2, itemName);
}