lundi 6 juin 2016

Do an action while any checkbox state is modified with Qt

In my programm, I fill my interface with a lot of checkbox by this way :

void VGCCC::addMaterialToUI(QDomNodeList _materialNodeList, QWidget* _areaWidget, QLayout* _layout, QWidget* _layoutWidget, int _maTable)
{
    for(int i=0; i< _materialNodeList.count();i++)
    {
        QDomElement materialElement = _materialNodeList.at(i).toElement();
        QString elementFile = materialElement.attribute("file");
        QString elementId = materialElement.attribute("id");
        QString elementLabel = elementId;
        elementLabel += "  -  ";
        elementLabel += materialElement.attribute("label");
        QCheckBox* checkbox = new QCheckBox(elementLabel);
        _layout->addWidget(checkbox);
        _layoutWidget->adjustSize();
        _areaWidget->setMinimumHeight(_layoutWidget->height());
        _areaWidget->setMinimumWidth(_layoutWidget->width());

        configuration c;
        c.path = (m_igmPath+elementFile).toStdString();
        c.id = elementId.toInt();
        c.name = elementLabel.toStdString();
        if(_maTable==0)
        {
            m_materialSectionMap[checkbox] = c;
        }
        else
        {
            m_materialPostMap[checkbox] = c;
        }
    }
}

I would like to know how to retrieve these "abstract" checkbox. More exactly, if one of these checkbox is checked, I would like to call another function like this :

    connect(anyCheckbox,SIGNAL(stateChanged(anyCheckbox)), this, SLOT(doSomethingFunctionIfCheckboxIsChecked()));

The difficulty is that in my UI, these checkbox didn't exist, so I can't connect them to my function. How can I solve it ?




Aucun commentaire:

Enregistrer un commentaire