Applying StyleSheet to Custom Window
-
Hi
I've been looking for an answer to this question on the forum but could not find anything. I am trying to apply a Stylesheet to a promoted widget but it just won't apply.
I used the Designer interface to promote a QWidget to a QWidget inherited class TitiWidget.
Still in the designer interface I added@
border: 2px solid green;
border-radius: 20px;
padding: 2px;
background-color: rgb(85, 85, 255);
@to the "StyleSheet" field of the now custom widget.
The widget's style is changed in the Design window but nothing is changed when I run the application. Demoting the Custom widget to a regular QWidget solves the problem and the style is applied.
I tried to add TitiWidget#widget or QWidget#widget before the stylesheet arguments. No improvements.
What should I do ?
-
-
-
[quote author="marcoB" date="1305200019"]why not in the constructor of TitiWidget put this ?
@
setStyleSheet(
"border: 2px solid green;"
"border-radius: 20px;"
"padding: 2px;"
"background-color: rgb(85, 85, 255);"
);@
[/quote]Because it all depends on how TitiWidget is implemented if this is going to work or not.
-
Thanks a lot for your answers.
The
@
void TitiWidget::paintEvent(QPaintEvent* /p_pEvent/)
{
QStyleOption opt;
opt.init(this);
QStylePainter p(this);
p.drawPrimitive(QStyle::PE_Widget, opt);
}
@trick works just fine. And it's actually in Qt's documentation. Shame on me.
Edit: please use code tags (@) before and after your code section; Andre