QPushButton changing between checkedOff / checkedOn .png graphics
-
Howdy,
I have a QPushButton that has 2 .png images that switch between checkedOn / checkedOff states and change between each image when I click on it. Is there a way to switch images without clicking on it, for example using a QTimer?
I wrote this pseudocode as an example:
QTimer::singleShot(5000, this, &TestClass::switchButtonImage); void TestClass::switchButtonImage() { QPixmap pixmap(":/button_ON.png"); QIcon buttonIcon(pixmap); ui.button01->setIcon(buttonIcon); } -
Howdy,
I have a QPushButton that has 2 .png images that switch between checkedOn / checkedOff states and change between each image when I click on it. Is there a way to switch images without clicking on it, for example using a QTimer?
I wrote this pseudocode as an example:
QTimer::singleShot(5000, this, &TestClass::switchButtonImage); void TestClass::switchButtonImage() { QPixmap pixmap(":/button_ON.png"); QIcon buttonIcon(pixmap); ui.button01->setIcon(buttonIcon); }@Calicoder
Did you try it? Looks reasonable to me. -
Hi,
Do you mean just replace the image or programmatically change your button state ?
-
Yes it will do the same as when you click on it.