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. Get Background Color when QPushButton is Pressed

Get Background Color when QPushButton is Pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt creatorc++qpalleteqcolor
2 Posts 2 Posters 2.6k 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.
  • T Offline
    T Offline
    toots
    wrote on last edited by toots
    #1

    Hi!

    How can I get QPushButton's pressed background color?

            if (isDown())
                _BGColor = <pressed back color>; //should get the pressed bg color
            else
                _BGColor = palette().color(QPalette::Background); //gets the idle/normal bg color , working fine
    

    I don't know if I can get my expected result when doing the above code.

    Thanks in advance!!!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      It is not clear what you want to do.

      If you have a few buttons with different background color and connected signal clicked to slo6t lets day onClick();

      and within such slot you want to find color of the button background which was clicked,
      first thing you need to find - which button was clicked.

      There are a few ways to find it.
      Simplest (not the best) is to call sender() within a slot.
      Cast ( use qobject_cast) to a QPushButton* ( or whatever your buttons are ),
      check its background if it is null.

      Why this way is not the best? It makes an assumption that slot is only called as a result of button click,
      which can't be guaranteed.

      It is better to use QSignalMapper.

      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