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. How to get row and column in QTablewidget?

How to get row and column in QTablewidget?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 10.6k 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.
  • M Offline
    M Offline
    mathi77in
    wrote on last edited by
    #1

    hi

    i create 3 row and column Qtablewidget. last column have QPushButton. How to write clicked() event?
    How to get particular row and column in Qtablewidget?

    i try...
    @QPushButton *btn_attempt = new QPushButton("CDiff");@
    @connect(btn_attempt, SIGNAL( cellClicked(int,int) ), this, SLOT( RemarksCall(int, int) ) );@

    @void tableDialog::RemarksCall(int row, int col)
    {
    QMessageBox msgBox;
    QTableWidgetItem* theItem = ui.tableWidget->item( row, col);
    QString theText = theItem->text();
    msgBox.about(this,"Testy",theText);
    }@

    but not get row and column value

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Hi,

      You can have a look in "here":http://qt-project.org/forums/viewthread/16673/ , There a QTableView is used instead of QTableWidget(your requirement).

      Your code work's for other cells in the tableWidget if i write,

      @ connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(remarksCall(int,int)));@

      Also try to Right Click on your pushButton. It will show a messageBox with row and columns. You need to handle for Left Click.

      You can have a look at "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details.

      Also in line 4 it should be

      @QTableWidgetItem* theItem = ui->tableWidget->item( row, col); @

      instead of ui.tableWidget :)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        QPushButton does not have a signal cellClicked(int,int). It has, for example, a clicked() signal, that you can connect to your slot. clicked() doesn't have any arguments, you'll have to do some bookkeeping yourself, for example using a [[Doc:QSignalMapper]].

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Skyrim
          wrote on last edited by
          #4

          hi, try this
          @
          connect(ui->tableWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(getText()));
          // or
          connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(getText()));
          @
          and
          @
          void tableDialog::getText(){
          QString text;
          text = ui->tableWidget->item(ui->tableWidget->currentRow(), ui->tableWidget->currentColumn())->text();
          }
          @

          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