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
Forum Updated to NodeBB v4.3 + New Features

Change color while the button is pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
colorbuttonc++
3 Posts 3 Posters 14.1k 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.
  • M Offline
    M Offline
    mandruk1331
    wrote on 31 Jan 2016, 10:20 last edited by
    #1

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

    Mandruk1331

    D 1 Reply Last reply 31 Jan 2016, 12:05
    0
    • M Offline
      M Offline
      michelson
      wrote on 31 Jan 2016, 10:44 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
      • M mandruk1331
        31 Jan 2016, 10:20

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

        D Offline
        D Offline
        Devopia53
        wrote on 31 Jan 2016, 12:05 last edited by
        #3

        @mandruk1331

        Hi,

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

        1 Reply Last reply
        0

        3/3

        31 Jan 2016, 12:05

        • Login

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