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. Using HSV for background-color?
Forum Updated to NodeBB v4.3 + New Features

Using HSV for background-color?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 800 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.
  • B Offline
    B Offline
    BoGut
    wrote on last edited by
    #1

    Hello fellow QT'ers,

    I've looked at the documentation and can't seem to find a way to use HSV values instead of RGB when declaring a background-color. Is this even possible? I've seen that QColor has a SetHSV method but how do you pass that into the background-color?

    Thanks in advance.

    1 Reply Last reply
    0
    • B BoGut

      Hi Christian, I took a look and only see a hardcoded color name "red".
      Here's what I've tried so far:

      QColor color;
      color.setHsv(206, 17, 97);
      this.setStyleSheet("QPushButton:checked { background-color: color; border: none }");
      

      and it's just compiling to a button with dark background.

      S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #6

      @BoGut You can use QColor::name() like this:

      this.setStyleSheet(QString("QPushButton:checked { background-color: %1; border: none }").arg(color.name()));
      
      B 1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        See https://doc.qt.io/qt-5/stylesheet-reference.html at the Color property

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • B Offline
          B Offline
          BoGut
          wrote on last edited by
          #3

          Hi Christian, I took a look and only see a hardcoded color name "red".
          Here's what I've tried so far:

          QColor color;
          color.setHsv(206, 17, 97);
          this.setStyleSheet("QPushButton:checked { background-color: color; border: none }");
          

          and it's just compiling to a button with dark background.

          S 1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            This code can not work. You pass a string to setStyleSheet so it can't catch the value of 'color'.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BoGut
              wrote on last edited by
              #5

              Ahhh right, I can pass it as a variable. Thanks I'll try and post an update once I get it to work.

              1 Reply Last reply
              0
              • B BoGut

                Hi Christian, I took a look and only see a hardcoded color name "red".
                Here's what I've tried so far:

                QColor color;
                color.setHsv(206, 17, 97);
                this.setStyleSheet("QPushButton:checked { background-color: color; border: none }");
                

                and it's just compiling to a button with dark background.

                S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #6

                @BoGut You can use QColor::name() like this:

                this.setStyleSheet(QString("QPushButton:checked { background-color: %1; border: none }").arg(color.name()));
                
                B 1 Reply Last reply
                3
                • S SimonSchroeder

                  @BoGut You can use QColor::name() like this:

                  this.setStyleSheet(QString("QPushButton:checked { background-color: %1; border: none }").arg(color.name()));
                  
                  B Offline
                  B Offline
                  BoGut
                  wrote on last edited by
                  #7

                  @SimonSchroeder that worked!

                  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