how to increment the number of pushbutton
-
I tried like this but x is not fixed there properly ..
here data =6for (samplerange = 1 ; samplerange <= data ; samplerange++) { QString x[6] = {"pushButton_100","pushButton_101","pushButton_102","pushButton_103","pushButton_104","pushButton_105"}; ui->x[counter++].setStyleSheet(QString("QPushButton {background-color: red;}")); } }
I want to increment the pushbutton number in code
like thispushButton_100 = button; for (samplerange = 1 ; samplerange <= data ; samplerange++) { ui->pushButton_100->setStyleSheet(QString("QPushButton {background-color: red;}")); } } button++;
-
I tried like this but x is not fixed there properly ..
here data =6for (samplerange = 1 ; samplerange <= data ; samplerange++) { QString x[6] = {"pushButton_100","pushButton_101","pushButton_102","pushButton_103","pushButton_104","pushButton_105"}; ui->x[counter++].setStyleSheet(QString("QPushButton {background-color: red;}")); } }
I want to increment the pushbutton number in code
like thispushButton_100 = button; for (samplerange = 1 ; samplerange <= data ; samplerange++) { ui->pushButton_100->setStyleSheet(QString("QPushButton {background-color: red;}")); } } button++;
@sankarapandiyan What is ui->x?!
Can you please explain more clearly what you're trying to do?
The code you posted does not make sense to be honest and is not even valid. -
@sankarapandiyan What is ui->x?!
Can you please explain more clearly what you're trying to do?
The code you posted does not make sense to be honest and is not even valid.@jsulm
If i give data = 6 as a input , so after that the 6 pushbutton need to highlight with red colour , Pb_1 ,pb_2 to upto Pb_6...
for this purpose i am using the for loop and tried to increment the Pb++ (pushbutton increment).So i wrote the code like this
pb_1 = button; for (samplerange = 1 ; samplerange <= data ; samplerange++) { ui->pb_1 ->setStyleSheet(QString("QPushButton {background-color: red;}")); } } button++;
But its not a good idea . say me some suggestions
-
@jsulm
If i give data = 6 as a input , so after that the 6 pushbutton need to highlight with red colour , Pb_1 ,pb_2 to upto Pb_6...
for this purpose i am using the for loop and tried to increment the Pb++ (pushbutton increment).So i wrote the code like this
pb_1 = button; for (samplerange = 1 ; samplerange <= data ; samplerange++) { ui->pb_1 ->setStyleSheet(QString("QPushButton {background-color: red;}")); } } button++;
But its not a good idea . say me some suggestions
@sankarapandiyan This is not valid C++ code.
If you want to iterate over your buttons in a loop then put pointers to these buttons into a QVector:QVector<QPushButton*> buttons; buttons->append(new QPushButton()); ... for (int i = 0; i < buttons.size(); ++i) { buttons[i] ->... }
This code is just to show how to do it, adapt it to your needs.
-
@sankarapandiyan This is not valid C++ code.
If you want to iterate over your buttons in a loop then put pointers to these buttons into a QVector:QVector<QPushButton*> buttons; buttons->append(new QPushButton()); ... for (int i = 0; i < buttons.size(); ++i) { buttons[i] ->... }
This code is just to show how to do it, adapt it to your needs.
@jsulm thanks a lot