Convert a QPushButton into another QPushButton

  • Hi,
    Is there any way to convert a QPushButton to another QPushButton?
    What I mean is, if for example I had a Start button, I would like for it to change to a Stop button when it is pressed.
    I know I could use two buttons, but I'm trying to achieve a clean User Interface and a minimalistic design without the clutter of buttons that are not enabled if another one is pressed.

    Thanks in advance.

  • Moderators

    You can create two buttons and hide one of them (instead of just disabling it) using hide()/show() or setVisible().

    You can also change the text with setText().

  • You can change the text or icon (setIcon()) as Chris mentioned. If you want to change the behavior you can have an if clause in the on_clicked() method. If you also want to change the color of the button you can use setStyleSheet().

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.