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. Selecting a row from a table
Forum Updated to NodeBB v4.3 + New Features

Selecting a row from a table

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

    I have a QTableView, and I use a QSortFilterProxyModel beetwen the model and the view.
    In the line:
    @ void MyWidget::mousePressEvent(QMouseEvent* event) @
    I'd like to select a row (I have 10 rows in the table) from the tableview:

    @
    QTableView temp = static_cast<QTableView>(this);
    QSortFilterProxyModel proxy = static_cast<QSortFilterProxyModel>(temp->model());
    QItemSelectionModel *selectionModel = temp->selectionModel();

    QModelIndexList indexes = selectionModel->selectedRows();
    @

    But my indexes has always 0 item. Why? What is wrong?

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

      I think mousePressEvent function is not what you really, because the function is probably called before the selection of the items. And be careful that this function will be called if you click any where on the widget, not just the row.

      You should connect a slot to the activate/clicked/pressed signal from the QTableView widget.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        [quote author="SaiyanRiku" date="1355136345"]I think mousePressEvent function is not what you really, because the function is probably called before the selection of the items. And be careful that this function will be called if you click any where on the widget, not just the row.

        You should connect a slot to the activate/clicked/pressed signal from the QTableView widget.[/quote]

        I (probably) need the mousePressEvent, because I'd like to drag (Drag and Drop) a line from my table. I have to make here a mimedata.

        How can I solve this anyway?

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

          I never use the drag and drop, but i think if you can't deal with activate/clicked/pressed signal you can try to get the index where the pointer is with the QTableView::indexAt and the mouse event position and merge it with selectedRows.

          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