Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Change button pressed color without adding a border to the button
Forum Updated to NodeBB v4.3 + New Features

Change button pressed color without adding a border to the button

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 483 Views 1 Watching
  • 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.
  • F Offline
    F Offline
    freemanl144
    wrote on last edited by
    #1

    I am using PyQT and have a button that, when pressed, I want it to change colors but I also want to remove the border. I was able to accomplish both of these, but not at the same time.

    I remove the border using

    self.ui.button_name.setStyleSheet("border: 0px;")
    

    And then I change the pressed function using

    self.ui.button_name.setStyleSheet("QPushButton:pressed {background-color: #BDBCBD};")
    

    When both are used together, the button does change color but then a rectangle is added around it. How can I both, remove the border and change the color when pressed?

    1 Reply Last reply
    0
    • SGaistS SGaist moved this topic from General and Desktop on
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should set all as a single stylesheet. What you do, from your description, is replace the first with the second.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should set all as a single stylesheet. What you do, from your description, is replace the first with the second.

        F Offline
        F Offline
        freemanl144
        wrote on last edited by
        #3

        @SGaist When I put them together nothing changes. I still have the grey rectangle around the button

        self.ui.button_name.setStyleSheet("QPushButton:pressed {background-color: #BDBCBD}; border: 0px;")
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you provide a minimal complete example to check what is happening ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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