Results 1 to 2 of 2

Thread: How to change push button text by clicking on another push button

  1. #1
    Join Date
    Apr 2020
    Posts
    4
    Qt products
    Qt5

    Default How to change push button text by clicking on another push button

    I added 2 Push buttons in ui like this qtt.jpg

    i added a slot for button "CLICK",

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to change push button text by clicking on another push button

    Call setText() on the other button object.

    Since you are using Designer you likely have two member variables accessible through the ui pointer:
    Qt Code:
    1. QPushButton *pushButton; // the "CLICK" button object
    2. QPushButton *pushButton2; // the other button object
    To copy to clipboard, switch view to plain text mode 
    then
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. ui->pushButton2->setText("CLICKED");
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. push button twice different text
    By Kloster in forum Newbie
    Replies: 10
    Last Post: 2nd September 2016, 19:17
  2. Replies: 7
    Last Post: 11th December 2014, 13:51
  3. Replies: 11
    Last Post: 8th February 2013, 14:59
  4. Use Push Button to change a variable
    By Qem1st in forum Newbie
    Replies: 4
    Last Post: 17th January 2013, 23:03
  5. How to change text color of push button?
    By augusbas in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 11:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.