PDA

View Full Version : Change text in QPushButton?



bizmopeen
10th February 2010, 19:18
Hello, all;

Is there a simple way to swap text on a QPushButton when it's toggled? I currently have it labeled as a "play" button and want it to display "pause" when clicked. Thanks in advance.

Lykurg
10th February 2010, 19:29
Hi,

use the toggled signal and connect it to following slot:
button->setText(button->isChecked() ? "pause" : "play");
Of course you can alter the code...

Lykurg

bizmopeen
10th February 2010, 20:20
Thank you, Lykurg! Is this the correct syntax?:


taStartPB->setText(taStartPB->isChecked() ? "Pause" : "Play");

taStartPB is the name of my QPushButton. Using this code seems to allow the program to run and compile, but will not switch the text when the button is toggled...

Lykurg
10th February 2010, 20:48
Yes it is. Alternatively you can use the bool delivered by the signal instead of checking the isChecked(). So is your slot reached? have you set of the signal-slot connection properly? Did you use setCheckable(true) for your button?

bizmopeen
10th February 2010, 22:25
I think I see the issue in my signal-slot connection. Thank you again!