Results 1 to 2 of 2

Thread: Inherited Style Sheet

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Inherited Style Sheet

    I have been unable to directly change a style sheet in a class inherited from QWidget, although it works when the class is QWidget. The simplified code that does not work (nothing in constructor):
    Qt Code:
    1. class Banner : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. Banner(QWidget *parent=0);
    6. ~Banner();
    7. };
    8.  
    9. banner = new Banner;
    10. banner->setStyleSheet("background-color: rgb(0, 100, 200);");
    To copy to clipboard, switch view to plain text mode 

    While this does work:

    Qt Code:
    1. banner = new QWidget;
    2. banner->setStyleSheet("background-color: rgb(0, 100, 200);");
    To copy to clipboard, switch view to plain text mode 

    I'm sure to have missed some understanding here and would appreciate help. Thanks

  2. #2
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Inherited Style Sheet

    Now if only I could read ALL the documentation!

    If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:

    Qt Code:
    1. void CustomWidget::paintEvent(QPaintEvent *)
    2. {
    3. opt.init(this);
    4. QPainter p(this);
    5. style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    It works fine now...

Similar Threads

  1. Style Sheet for custom widget
    By 1111 in forum Qt Programming
    Replies: 3
    Last Post: 31st August 2010, 12:52
  2. QTabWidget transparent background problem
    By destroyar0 in forum Qt Programming
    Replies: 10
    Last Post: 25th June 2009, 12:19
  3. QMenu style sheet: works in dev env, breaks in release
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2008, 19:18
  4. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 08:38
  5. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22

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.