Qtablewidget and QModelIndex
-
hello,
ui->tableWidget_show->setRowCount(30); ui->tableWidget_show->setColumnCount(7); QModelIndex index = ui->tableWidget->currentIndex(); QString itemText = index.data(Qt::DisplayRole).toString(); ui->tableWidget_show->setHorizontalHeaderLabels(QStringList()<<itemText);
when i click an item on the tablewidget i want to show it in the tablewidget_show but it is not work how can i do this ?
-
-
Hi
What does debugger show?
You could test with ui->tableWidget_show->setHorizontalHeaderLabels(QStringList()<<"Test");
and see if that works. then you know you dont get right text. -
if i do this it shows that but i dont want this i want to get selected item from tablewidget
-
Every time you want that "when you do something then something else happens" it means that you need a
connect
connect(ui->tableWidget->selectionModel(),&QItemSelectionModel::currentIndexChanged,[=](const QModelIndex& idx)->void{ui->tableWidget_show->model->setHeaderData(0,Qt::Horizontal,idx.data());});
-
thank you for help, i will keep in mind what you said