Results 1 to 5 of 5

Thread: stylesheets with RGB

  1. #1
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default stylesheets with RGB

    Hi,

    Normally this is how I use to set the background color of my pushbutton:
    Qt Code:
    1. colorButton->setStyleSheet("background:red;");
    To copy to clipboard, switch view to plain text mode 
    But how do you do it using RGB colors?
    This doesn't work:
    Qt Code:
    1. colorButton->setStyleSheet("background:QColor(200,100,150);");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stylesheets with RGB

    you do it like this
    Qt Code:
    1. colorButton->setStyleSheet("background:rgb(200,100,150);");
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to eric for this useful post:

    tommy (12th December 2007)

  4. #3
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stylesheets with RGB

    But why doesn't it work with variables, like below?

    Qt Code:
    1. int rand1 = 100 + qrand()%155;
    2. int rand2 = 100 + qrand()%155;
    3. int rand3 = 100 + qrand()%155;
    4. colorButton->setStyleSheet("background:rgb(rand1,rand2,rand3);");
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Nov 2007
    Location
    Russia, Moscow
    Posts
    21
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheets with RGB

    Because "background:rgb(rand1,rand2,rand3);" is a string.. and u have "rand1" as a string, not as a number.
    Use
    Qt Code:
    1. QString("background:rgb(%1,%2,%3);").arg(rand1).arg(rand2).arg(rand3)
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to ModeZt for this useful post:

    tommy (12th December 2007)

  7. #5
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stylesheets with RGB

    Quote Originally Posted by tommy View Post
    Hi,

    Normally this is how I use to set the background color of my pushbutton:
    Qt Code:
    1. colorButton->setStyleSheet("background:red;");
    To copy to clipboard, switch view to plain text mode 
    But how do you do it using RGB colors?
    This doesn't work:
    Qt Code:
    1. colorButton->setStyleSheet("background:QColor(200,100,150);");
    To copy to clipboard, switch view to plain text mode 
    background: #RRGGBB
    also works, where RR, GG, and BB are colour values in hex. ie #FFFFFF being white.

Similar Threads

  1. Replies: 1
    Last Post: 27th November 2007, 10:10
  2. QPushButton, stylesheets, text alignment
    By SiLiZiUMM in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 19:53
  3. QLabel in StyleSheets isn't working?
    By VireX in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2007, 09:59
  4. Replies: 1
    Last Post: 5th March 2007, 20:50
  5. Problem mit Stylesheets
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2006, 20:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.