Results 1 to 4 of 4

Thread: Style sheet not applied by inheritance ?

  1. #1
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Style sheet not applied by inheritance ?

    Hi,

    I have a MyWidget object which inherits from QWidget.

    The following function is supposed to change the background color of a MyWidget object but it does not work.

    Any remarks ?

    Thanks.

    Qt Code:
    1. // Set a color
    2. void MyWidget::setColor(const QColor &color)
    3. {
    4.  
    5. // Prepare the style
    6. QString style = "background-color: rgb(%1, %2, %3);";
    7.  
    8. // Set the color
    9. this->setStyleSheet(
    10. style
    11. .arg(color.red())
    12. .arg(color.green())
    13. .arg(color.blue())
    14. );
    15.  
    16. qDebug() << this->styleSheet();
    17. }
    To copy to clipboard, switch view to plain text mode 

    PS : the debug instruction returns the correct style sheet.
    Last edited by moijhd; 2nd April 2013 at 16:22.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Style sheet not applied by inheritance ?

    Please define "does not work".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Style sheet not applied by inheritance ?

    The background color of the widget does not change.

    What I am trying to achieve here is the following : the user select a color (in a QDialogColor for example) and then I want to draw a rectangle with the chosen color. I did not find a appropriate tool. More precisely I would like to have a button instead...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Style sheet not applied by inheritance ?

    If you want to draw a rectangle then reimplement the paint event and use QPainter::drawRect()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  2. KDE 3 style applied to Qt 4 programs
    By alecs1 in forum KDE Forum
    Replies: 4
    Last Post: 4th December 2008, 21:24
  3. Style Sheet on QWizard
    By desch in forum Qt Programming
    Replies: 2
    Last Post: 6th December 2007, 17:12
  4. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 08:38
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 13:05

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.