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 ?



  • 0_1542371008687_1e4b90af-fce4-4bc4-8004-2a240fc3129a-image.png


  • Qt Champions 2017

    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

    0_1542371801973_7ded45e8-4ff2-4578-b0e6-2eabf8ef8aa1-image.png



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.