QObject::connect(ui->tableWidget_4, &QTableWidget::itemSelectionChanged,[=](){
QList<QTableWidgetItem *> selectedItems = ui->tableWidget_4->selectedItems();
if (!selectedItems.isEmpty()) {
int selectedColumn = selectedItems.first()->column();
qDebug() << "Selected column:" << selectedColumn;
QStringList itemsInSelectedColumn;
for (int row = 0; row < ui->tableWidget_4->rowCount(); ++row) {
QTableWidgetItem *item = ui->tableWidget_4->item(row, selectedColumn);
if (item) {
itemsInSelectedColumn.append(item->text());
}
}
qDebug() << "Items in selected column:";
qDebug() << itemsInSelectedColumn;
}
});
标签:qt,QTableWidget,selectedItems,按列,item,tableWidget,ui,row
From: https://blog.csdn.net/qq_45662588/article/details/140947171