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. QTableWidget QCheckbox extract values iteration
Forum Updated to NodeBB v4.3 + New Features

QTableWidget QCheckbox extract values iteration

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 239 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.
  • Kalbo85K Offline
    Kalbo85K Offline
    Kalbo85
    wrote on last edited by
    #1

    The values of the table are save using QSettings, ans once the program starts, the values are loaded into the table in this way (just the first row)::

    void StatusConfigPage::setStatusTable(){
    
        // Set Checkbox
        QSettings statusSettings("Rasper", "Interface");
        statusSettings.beginReadArray("status");
    
        for (int dataIndex = 0; dataIndex < dataClassArrayLength; dataIndex++){
            statusSettings.setArrayIndex(dataIndex);
    
            QTableWidgetItem *item = new QTableWidgetItem();
            item->data(Qt::CheckStateRole);
            statusTable->setItem(0, dataIndex, item);
            bool valueTemp;
            valueTemp = statusSettings.value("cellValue").toBool();
            if(valueTemp){
                item->setCheckState(Qt::Checked);
            } else {
                item->setCheckState(Qt::Unchecked);
            }
        }
    

    After manipulating the values of the QCheckboxes, the ones of the first row set on statusTable are intended to be store in this way:

    void StatusConfigPage::updateSettings(){
    
        QSettings statusSettings("Rasper", "Interface");
    
            statusSettings.beginWriteArray("status");
    
            for (int dataIndex = 0; dataIndex < dataClassArrayLength; dataIndex++) {
                statusSettings.setArrayIndex(dataIndex);
    
                bool valueTemp;
    
                QTableWidgetItem *item = statusTable->itemAt(0,dataIndex);
                if(item->checkState()==Qt::Checked){
                    valueTemp = true;
                } else {
                    valueTemp = false;
                }
                statusSettings.setValue("cellValue", valueTemp);
            }
                statusSettings.endArray();
    }
    

    I don't know exactly where or why, probably trying to save them (in updateSettings()), it is taking the value of the first element (statusTable->itemAt(0,dataIndex))) and saving it for the rest of the elements.

    Thanks in advance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      ItemAt takes "on widget" coordinates.
      What you want to use is the item function.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Kalbo85K Offline
        Kalbo85K Offline
        Kalbo85
        wrote on last edited by
        #3

        Thanks SGaist,
        it works now! I didn't see that the function itemAt was giving back the pointer.

        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