How to change texts and image by button multiple times
-
You connect to the button’s
clickedsignal. From there you callsetPixmap()andsetText()on the object you want to change. If you want to toggle between two or more combinations of pixmaps/texts, you have to implement a counter. -
Hi,
In addition to what @Axel-Spoerl wrote, since you mention a story it looks like you will have some linear progress so maybe consider a state machine for that and on each click you'll advance one state. With each state you'll operate the updates required.
-
You connect to the button’s
clickedsignal. From there you callsetPixmap()andsetText()on the object you want to change. If you want to toggle between two or more combinations of pixmaps/texts, you have to implement a counter.@Axel-Spoerl ok but how do i make this counter. I tried to do it with if and a form similar to a variable that incremented for each click of the button the variable adds one more and this variable would go to the next situation, but it doesn't work. how would i actually make this counter
-
Hi,
In addition to what @Axel-Spoerl wrote, since you mention a story it looks like you will have some linear progress so maybe consider a state machine for that and on each click you'll advance one state. With each state you'll operate the updates required.
-
Hi,
In addition to what @Axel-Spoerl wrote, since you mention a story it looks like you will have some linear progress so maybe consider a state machine for that and on each click you'll advance one state. With each state you'll operate the updates required.
-
The state machine is well documented, just examine the examples.
If you want to implement a counter, I wonder if you have heard about static variables within a method and the modulo operator. That’s the simple solution if your text/image pattern always follows the same direction.
Your slot would look like this:Void yourClass::onButtonClicked { const int numberStates = 3; // or whatever the number of your states is static int counter = numberStates -1; ++counter %= numberStates; // increment and start over after last state switch (counter) { case 0: // set first image and text break; case 1: // set second image and text break; case 2: // set third image and text break; } } -
@milhao said in How to change texts and image by button multiple times:
@SGaist where the state machine and keyboard is outside the class or inside the class
That question is really unclear. Can you explain what the issue is ?
-
@milhao said in How to change texts and image by button multiple times:
@SGaist where the state machine and keyboard is outside the class or inside the class
That question is really unclear. Can you explain what the issue is ?
-
Sure you can use the same button for the sequence.