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. [SOLVED] QTableWidget
QtWS25 Last Chance

[SOLVED] QTableWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.9k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello, I am trying to read a string from QTableWidget (current row) when button in table is clicked... So when I click PushButton in row 1, it should print string from one column...

    Problem is, when I press on the PushButtton, it does not take index of current row... index does not change at all... Buttons are not connected with QTableWidget at all...

    I ran application and printed current index... When I ran app and press button, current index is -1... It should inherit index of row in which button is located... I can click on any button and index won't change... I will change only if I click on any item in QTable...

    This code works, but does not do what I want...

    1. I must press on item first, to obtain current index and print string at all...
    2. If I click on item in row 1 and press button in row 3, it will show me string from row 1 (because index is set to row 1)...
      @int row = ui->tableWidget->currentRow();
      QString str = ui->tableWidget->item(row, 3)->text();
      qDebug() << str;@

    How to get current row of a clicked button??? It seems like button and other parts in that row are not connected... Even when I click to any item, all items in that row highlight, but not also button...

    @ int row = ui->tableWidget->rowCount();
    ui->tableWidget->setRowCount(row+1);
    QTableWidgetItem *name = new QTableWidgetItem("Name");
    QTableWidgetItem *time = new QTableWidgetItem("Time");
    QTableWidgetItem *duration = new QTableWidgetItem("Duration");
    QTableWidgetItem *location = new QTableWidgetItem("Location");
    QTableWidgetItem *size = new QTableWidgetItem("Size");
    btn = new QPushButton("PushButton");
    ui->tableWidget->setCellWidget(row, 5, btn);
    ui->tableWidget->setItem(row, 0, name);
    ui->tableWidget->setItem(row, 1, time);
    ui->tableWidget->setItem(row, 2, duration);
    ui->tableWidget->setItem(row, 3, location);
    ui->tableWidget->setItem(row, 4, size);@

    !http://imageshack.com/a/img43/3640/s23k.png(i)!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I found solution...

      @int row;
      int col;

      for(row=0; row < ui->tableWidget->rowCount(); row++){
        for(col=0; col < ui->tableWidget->columnCount(); col++){
      
            if(sender() == ui->tableWidget->cellWidget(row,col)){
             QString str = ui->tableWidget->item(row, 3)->text();
             qDebug() << str;
          }
         }
      }
      

      @

      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