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. QTableView, set arbitrary selection of rows.
Qt 6.11 is out! See what's new in the release blog

QTableView, set arbitrary selection of rows.

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

    I'm using a QTableView with a custom model. I want to change the arbitrary selection of rows after a manipulation of the model data.

    So first row 1,5,8 are selected, then the data of these rows are moved upwards in the vector, and the selection should also move upwards, to 0,4 and 7. But there seems no method for setting a selection in a QTableView. Am I missing something?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroen3
      wrote on last edited by
      #2

      Well. I got it. It think. Almost all roads are a dead end for requiring a QModelIndex (which you cannot create from a Row/Col), or bump into a protected method.

      The most obvious solution is using, QTableView::setSelection. But it's protected.
      So you cannot access that from your model, or from the QMainWindow.

      But there seems to be this way:
      ui->tableView->selectionModel()->select(ui->tableView->model()->index(row,0) ,QItemSelectionModel::Toggle|QItemSelectionModel::Rows);

      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