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. Is there a deselectRow for QTableView?
Forum Updated to NodeBB v4.3 + New Features

Is there a deselectRow for QTableView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 290 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have a table like this:

    c224e660-6bf9-445d-a479-f5d0b56ffc4e-image.png

    83b2ed48-aba6-423e-bba4-18a53d4c5e7f-image.png

    I want to sync the checkbox and selection, and am wondering whether a deselect row feature exists: the way I have implemented it so far is like this:

    void TestConfig::checkBoxSelectionSync(){
        //Detects whether the two are out of sync by checking whether the row activated is the same as the button clicked.
        for(int i = 0 ; i < ui->tableWidget_Configs->rowCount();i++){
            QTableWidgetItem *button = ui->tableWidget_Configs->item(i, 0);
            bool buttonSelected = button->checkState();
            if (buttonSelected != ui->tableWidget_Configs->item(i, 0)->isSelected()){
                ui->tableWidget_Configs->selectRow(i);   //Selects the line or deselects the line
            }
        }
    }
    

    I don't think selectRow is deselecting my rows and I haven't found anything in the documentation on this regard. Please let me know if more info is required.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have a table like this:

      c224e660-6bf9-445d-a479-f5d0b56ffc4e-image.png

      83b2ed48-aba6-423e-bba4-18a53d4c5e7f-image.png

      I want to sync the checkbox and selection, and am wondering whether a deselect row feature exists: the way I have implemented it so far is like this:

      void TestConfig::checkBoxSelectionSync(){
          //Detects whether the two are out of sync by checking whether the row activated is the same as the button clicked.
          for(int i = 0 ; i < ui->tableWidget_Configs->rowCount();i++){
              QTableWidgetItem *button = ui->tableWidget_Configs->item(i, 0);
              bool buttonSelected = button->checkState();
              if (buttonSelected != ui->tableWidget_Configs->item(i, 0)->isSelected()){
                  ui->tableWidget_Configs->selectRow(i);   //Selects the line or deselects the line
              }
          }
      }
      

      I don't think selectRow is deselecting my rows and I haven't found anything in the documentation on this regard. Please let me know if more info is required.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to access the QItemSelectionModel directly and use QItemSelectionModel::select() with the appropriate flags to deselect a row.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved