Results 1 to 5 of 5

Thread: Change text in QPushButton?

  1. #1
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Change text in QPushButton?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Change text in QPushButton?

    Hi,

    use the toggled signal and connect it to following slot:
    Qt Code:
    1. button->setText(button->isChecked() ? "pause" : "play");
    To copy to clipboard, switch view to plain text mode 
    Of course you can alter the code...

    Lykurg

  3. #3
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Change text in QPushButton?

    Thank you, Lykurg! Is this the correct syntax?:

    Qt Code:
    1. taStartPB->setText(taStartPB->isChecked() ? "Pause" : "Play");
    To copy to clipboard, switch view to plain text mode 

    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...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Change text in QPushButton?

    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?

  5. The following user says thank you to Lykurg for this useful post:

    bizmopeen (10th February 2010)

  6. #5
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Change text in QPushButton?

    I think I see the issue in my signal-slot connection. Thank you again!

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Change Opacity of QPushButton
    By DiamonDogX in forum Qt Programming
    Replies: 3
    Last Post: 5th November 2010, 12:09
  3. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  4. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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.