accessing multiple pushbutton objects from a loop
-
I nave an application the I have created multiple push buttons in a group. I need to change the background color and text based on a global bit and a button selection to change the text. Below is the code for one button, but I need to extend the changes to 64 buttons.
unsigned long long gagset = 0, gagset2 = 0;
bool highgag = false;void ToolsetPanel::on_Gag_PB_1_clicked()
{
if(highgag == true){
ui->Gag_PB_1->setText("65");
}
else {
ui->Gag_PB_1->setText("1");
}ui->Gag_PB_1->setStyleSheet(colorButton(gagset & 1)); if(gagset && 1 == true) gagset &= ~1; else gagset |= 1;
}
void ToolsetPanel::on_Gag_PB_65_clicked()
{
if(highgag == true){
ui->Gag_PB_65->setText("1-64");
highgag = false;
}
else
{
ui->Gag_PB_65->setText("65-128");
highgag = true;
}
}When tool 65 is selected in need to change the values of all the buttons and the backgrounds if the button has been previously selected according to the bit values of highgag2;
I hope someone can help me with this. I can individually address each button, but it would be better if I could access them as a group.
dencla
-
I nave an application the I have created multiple push buttons in a group. I need to change the background color and text based on a global bit and a button selection to change the text. Below is the code for one button, but I need to extend the changes to 64 buttons.
unsigned long long gagset = 0, gagset2 = 0;
bool highgag = false;void ToolsetPanel::on_Gag_PB_1_clicked()
{
if(highgag == true){
ui->Gag_PB_1->setText("65");
}
else {
ui->Gag_PB_1->setText("1");
}ui->Gag_PB_1->setStyleSheet(colorButton(gagset & 1)); if(gagset && 1 == true) gagset &= ~1; else gagset |= 1;
}
void ToolsetPanel::on_Gag_PB_65_clicked()
{
if(highgag == true){
ui->Gag_PB_65->setText("1-64");
highgag = false;
}
else
{
ui->Gag_PB_65->setText("65-128");
highgag = true;
}
}When tool 65 is selected in need to change the values of all the buttons and the backgrounds if the button has been previously selected according to the bit values of highgag2;
I hope someone can help me with this. I can individually address each button, but it would be better if I could access them as a group.
dencla
-
@dencla54 said in accessing multiple pushbutton objects from a loop:
I can individually address each button, but it would be better if I could access them as a group.
Put them in a
QButtonGroup
or some container likeQVector
and iterate them