Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change color while the button is pressed

Change color while the button is pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
colorbuttonc++
3 Posts 3 Posters 14.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by
    #1

    How I can change the button color while it's pressed?

    Mandruk1331

    D 1 Reply Last reply
    0
    • M Offline
      M Offline
      michelson
      wrote on last edited by
      #2

      Connect suitable slot to the clicked(bool) buttons signal.

      void on_btn_clicked() 
      {
          ui->btn->setStyleSheet("QPushButton{ background-color: yellow }");
      }
      /*...*/
      connect(ui->btn, SIGNAL(clicked(bool)), this,SLOT(on_btn_clicked()));
      //not tested
      
      1 Reply Last reply
      1
      • mandruk1331M mandruk1331

        How I can change the button color while it's pressed?

        D Offline
        D Offline
        Devopia53
        wrote on last edited by
        #3

        @mandruk1331

        Hi,

        yourButton->setStyleSheet("QPushButton:pressed { background-color: red }");

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved