Group of Checkboxes



  • Hello I have 16 checkboxes and they have similar task to hide graph on qcustomplot can I do this in one method?

    void checkBoxStateChanged(int state) //1
    	{
    	    if(state)
    	    {  
    	      plot->graph(0)->setVisible(false);
    	    }
    	    else
    	    {
    	       plot->graph(0)->setVisible(true);
    	    }  
    	    
    	};
    


  • Create QButtonGroup and add buttons to it. Then connect buttonGroup to slot function which has functions for all buttons.
    In this way you don't have to create slot functions for each button. You need only one slot function for all buttons.

     buttonGroup = new QButtonGroup(this);
     buttonGroup->setExclusive(false);
     buttonGroup->addButton(textButton, InsertTextButton);
     connect(buttonGroup, SIGNAL(buttonClicked(int)),
             this, SLOT(buttonGroupClicked(int)));
    
     void buttonGroupClicked(int id)
     {
         QList<QAbstractButton *> buttons = buttonGroup->buttons();
         foreach (QAbstractButton *button, buttons) {
         if (buttonGroup->button(id) != button)
             button->setChecked(false);
         }
         if (id == InsertTextButton) {
         } else {
         }
     }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.