PDA

View Full Version : StyleSheets on a custom widget plugin



AwareWolf
11th December 2009, 21:06
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?

SABROG
12th December 2009, 20:36
You need add this:



void Widget::paintEvent(QPaintEvent *event)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

AwareWolf
14th December 2009, 14:36
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?