Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change the display of the button when pressed?



  • Hi.
    How to change the display of the button when pressed?
    Initially set the button style:

     ui->register_Button->setStyleSheet(QString::fromUtf8("background-color: rgb(43, 104, 255); color:white; border: 3px solid white; padding: 5px; border-radius: 10px;"));
    

    When pressed on the signal, the pressed () set the change button

    ui->register_Button->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 209, 202); color:white; border: 3px solid white; padding: 5px; border-radius: 10px;"));
    

    How to return the button to its original state after moving the mouse to another place or after the button is triggered?


  • Moderators

    @Mikeeeeee

    QPushButton comes with a pressed state for your stylesheet ->

    ui->register_Button->setStyleSheet("QPushButton{background-color: rgb(43, 104, 255); color:white; border: 3px solid white; padding: 5px; border-radius: 10px;} QPushButton:pressed{background-color: rgb(0, 209, 202); color:white; border: 3px solid white; padding: 5px; border-radius: 10px;}");
    

Log in to reply