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 way to see which objects have recently been deselected?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to see which objects have recently been deselected?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 151 Views
  • 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

    I have the following code which triggers every time itemSelection is changed

    void TestConfig::on_tableWidget_Configs_itemSelectionChanged(){
        //Determine if item is selected or not.
        //Make a list of all the crap that is selected.
        QModelIndexList selected = ui->tableWidget_Configs->selectionModel()->selectedRows();
        for(int i = 0; i < ui->tableWidget_Configs->rowCount(); i++){   //Unchecks everything. This is a bad way of doing it.
            ui->tableWidget_Configs->item(i, 0)->setCheckState(Qt::Unchecked);
            qDebug() << "Line " << i << " unchecked";
        }
    
        for(int i = 0; i < selected.size(); i++){
            int r = selected.at(i).row();
            qDebug() << selected.at(i).row();
            ui->tableWidget_Configs->item(r, 0)->setCheckState(Qt::Checked);
            qDebug() << "Line " << r << " checked";
        }
    }
    

    I am wondering whether there is a function that would allow one to see which objects have recently been deselected so that I won't have to uncheck everything every time.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      I have the following code which triggers every time itemSelection is changed

      void TestConfig::on_tableWidget_Configs_itemSelectionChanged(){
          //Determine if item is selected or not.
          //Make a list of all the crap that is selected.
          QModelIndexList selected = ui->tableWidget_Configs->selectionModel()->selectedRows();
          for(int i = 0; i < ui->tableWidget_Configs->rowCount(); i++){   //Unchecks everything. This is a bad way of doing it.
              ui->tableWidget_Configs->item(i, 0)->setCheckState(Qt::Unchecked);
              qDebug() << "Line " << i << " unchecked";
          }
      
          for(int i = 0; i < selected.size(); i++){
              int r = selected.at(i).row();
              qDebug() << selected.at(i).row();
              ui->tableWidget_Configs->item(r, 0)->setCheckState(Qt::Checked);
              qDebug() << "Line " << r << " checked";
          }
      }
      

      I am wondering whether there is a function that would allow one to see which objects have recently been deselected so that I won't have to uncheck everything every time.

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

      Also here you have to go through the QItemSelectionModel and it's selectionChanged() signal.

      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