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. [Solved] Change color of push button
Forum Updated to NodeBB v4.3 + New Features

[Solved] Change color of push button

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 9.6k 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.
  • M Offline
    M Offline
    moravas
    wrote on last edited by
    #1

    Hi Folks,

    I would like to create a pushBotton on my UI, but I need to change its color by specific user action. The first, I tried to change it on the UI designer: I clicked on the styleSheet property, but the setted color doesn't have any affect.
    Can anybody help me, how can I change the color?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      I put the following in the styleSheet property of a push button and it worked for me.

      @background-color: rgb(255, 43, 39);@

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moravas
        wrote on last edited by
        #3

        Hi,

        this also works for me, but I only see this color when the button is pressed. After the release the button color set back to the default.

        Regards,
        Norbert

        1 Reply Last reply
        0
        • S Offline
          S Offline
          steno
          wrote on last edited by
          #4

          Can you post exactly what your stylesheet looks like?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            moravas
            wrote on last edited by
            #5

            Hi,

            if I open the styleSheet editor, I see the following line:
            @
            color: rgb(97, 255, 24);
            @

            This is some green color, but my buttons appers with the default grey color.

            Regards,
            Norbert

            Update:

            I found the following solution that works for me (little bit in pseudo code):
            @
            QPushButton instance->setStyleSheet("border: 1px; border-radius: 6px; background-color: " + QColor instance.name());
            @

            The "simple" change of the background-color didn't work, because the "border" property was not specified.

            Regards,
            Norbert

            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