Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qtablewidget and QModelIndex
Forum Updated to NodeBB v4.3 + New Features

Qtablewidget and QModelIndex

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    veysel.olgun
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      veysel.olgun
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          veysel.olgun
          wrote on last edited by veysel.olgun
          #4

          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

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5

            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());});

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3
            • V Offline
              V Offline
              veysel.olgun
              wrote on last edited by
              #6

              thank you for help, i will keep in mind what you said

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved