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 access the text of Qtablewidget when selection behavior is select rows
Forum Updated to NodeBB v4.3 + New Features

How to access the text of Qtablewidget when selection behavior is select rows

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

    I want to access the text of first column of the currently selected row, but I can't find a way similar to that of QtreeWidget.

    @ if(ui->treewidget ->currentItem()->text(0)=="Something")
    // then do something
    @

    but Qtablewidget doesn't support such a feature. So what to do.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      The table widget equivalent of your tree widget code would be something like:

      @
      int row = ui->tableWidget->currentRow();
      QString text = ui->tableWidget->item(row, 0)->text();
      @

      The current item and current selection are not necessarily related though. If you allow only single selection and have QAbstractItemView::SelectRows set then QTableWidget::selectedItems() should contain only one item with row == 0.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adnan
        wrote on last edited by
        #3

        thanks a lot for such a nice reply!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adnan
          wrote on last edited by
          #4

          There is a bit problem with
          @ ui-

          tableWidget->item( row, 0)-
          text();
          @

          the program crashes at this statement if the row is empty, if there is no 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