Results 1 to 3 of 3

Thread: StyleSheets on a custom widget plugin

  1. #1
    Join Date
    Dec 2009
    Location
    New Hampshire, USA
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default StyleSheets on a custom widget plugin

    I have a custom widget plugin that derives from QWidget only, so doesn't extend a "normal" control. To get style sheet functionality, it seems I have to implement into my class the ability to get the style sheet, parse it, and use the result appropriately in my paintEvent() method. Is this correct, or am I doing more work than is necessary?

    IOW, what can a custom widget plugin that inherits QWidget only do with stylesheets?

  2. #2
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: StyleSheets on a custom widget plugin

    You need add this:

    Qt Code:
    1. void Widget::paintEvent(QPaintEvent *event)
    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 

  3. #3
    Join Date
    Dec 2009
    Location
    New Hampshire, USA
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: StyleSheets on a custom widget plugin

    Thank you, Sabrog, for the advice; I will look into the QStyleOption class. However, maybe you can tell me:

    Does the QStyleOption class, or any other class, help me out with non-standard declarations? For example, if I have a widget that will change color based on a custom class specific state, like Selectable, Not Selectable, Active, Complete. In my stylesheet I might have this:

    selectable-color:white;
    nonselectable-color:green;
    active-color:blue;
    complete-color:red;

    As far as I can see, I will need to parse the stylesheet myself in my class implementation to get these colors. Am I right?

Similar Threads

  1. Replies: 5
    Last Post: 21st February 2007, 22:11
  2. Replies: 2
    Last Post: 25th August 2006, 11:35
  3. Custom Widget Plugin Analog Clock
    By kemp in forum Qt Programming
    Replies: 8
    Last Post: 11th August 2006, 13:22
  4. How to initialize properties to a custom plugin widget?
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2006, 16:56
  5. Replies: 12
    Last Post: 15th February 2006, 10:46

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.