PDA

View Full Version : How to change push button text by clicking on another push button



mcraellehs
17th April 2020, 00:01
I added 2 Push buttons in ui like this 13398

i added a slot for button "CLICK",


void MainWindow::on_pushButton_clicked()
{

}

when i click on this button "CLICK" i want the button's "BUTTON" text to be changed to "CLICKED".
How can i do that ?

ChrisW67
17th April 2020, 01:06
Call setText() on the other button object.

Since you are using Designer you likely have two member variables accessible through the ui pointer:


QPushButton *pushButton; // the "CLICK" button object
QPushButton *pushButton2; // the other button object

then

void MainWindow::on_pushButton_clicked()
{
ui->pushButton2->setText("CLICKED");
}