PDA

View Full Version : Style Sheet for custom widget



1111
23rd March 2009, 11:28
Hi all,

I made my custom widget based on QWidget, just several button and labels. How to set style sheet from my custom widget?

I set object name for widget

myWidget->setObjectName("myWidget");

and wrote small style sheet

QWidget#myWidget {
color: red;
}

but nothing happened. :o

The reason why I want to do it this way is because I want to have something like this in the future:


QWidget#myWidget > QPushButton {
color: red;
}

Lykurg
23rd March 2009, 15:02
Oh, I had this problem time ago myself, but I can't remember exactly the solution (and even find it now...) But you must either set autofillbackground or even provide a paintEvent() in your subclassed widget...


MyWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
}

1111
24th March 2009, 13:47
Thanks mate! It helps! :cool:


Oh, I had this problem time ago myself, but I can't remember exactly the solution (and even find it now...) But you must either set autofillbackground or even provide a paintEvent() in your subclassed widget...


MyWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
}

amras
31st August 2010, 12:52
Could you please provide some snippets of your code? I have the same problem and the solution doesn't work for me.
I have Qt 4.6 btw