[Solved] How to Toggle qpushbutton name
-
wrote on 9 Dec 2014, 15:30 last edited by
hello guys i want to toggle qpushbutton name means when i hit the push button once, push button should have name as "add" and when i hit it again it should have sub and when i hit it gain it should show again add.
How can i do it
plz help me guys
Thanks -
Hi,
Use a slot connected to the clicked() signal, or if you are using a checkable button the toggled(bool) signal.
In the slot, verify the current text and change it accordingly or if your button is checkable, update the name based on whether the button is checked or not.
[edit: corrected wrong wording]
-
wrote on 9 Dec 2014, 15:46 last edited by
@addButton = new QPushButton(tr("add"));
connect(addButton, SIGNAL(clicked()),this, SLOT(slotButtonaddPressed()));void abcd:slotButtonaddPressed()
{
hideButton->setText(tr("sub"));
}
@I have done this now when i clicked 3rd time it shows "sub" only i want add when i press 3rd time how can i do that
thanks -
You haven't implemented the "verify the button name" part
-
wrote on 9 Dec 2014, 15:54 last edited by
verify means
how can i do it
Help -
Verify means: test what the current QPushButton text is and then set the other one.
-
wrote on 9 Dec 2014, 16:12 last edited by
with which function i can check the name of pushbutton i know i have to use it in If statement
Can u give on example related to my one.
Thanks -
Use the "text":http://qt-project.org/doc/qt-5/qabstractbutton.html#text-prop property
-
wrote on 9 Dec 2014, 16:21 last edited by
@if(addButton->text=="add")
{
addButton->setText(tr("sub"));
}
else
{
addButton->setText(tr("add"));
}@
i wrote like this but it not working it not building the program -
wrote on 9 Dec 2014, 16:35 last edited by
Thank you very much SGaist it worked
Thanks alot
1/10