[Interest] About Qt StyleSheet

Elvis Stansvik elvstone at gmail.com
Tue May 31 17:04:32 CEST 2016


2016-05-31 16:20 GMT+02:00 André Somers <andre at familiesomers.nl>:

> Hi,
>
> What I _think_ happens is that you currently are using a style that does
> not support style sheets. Only build in styles do, up to a point. If you
> then apply a style sheet, Qt probably switches to a fall-back style that
> _does_ support style sheets, but that has an effect on other widgets as
> well as you noticed.
>
> I'd steer clear of using style sheets if you can. They generally end up
> being more trouble than the're worth even though it seems like a simple
> technique to use at first.
>
I'd also stay clear of style sheets. What you can try instead is modifying
the foreground role of the palette with something like

    QPalette palette = ui.newGroupNameLabel->palette();
    palette.setColor(ui.newGroupNameLabel->foregroundRole(), Qt::black);
    ui.newGroupNameLabel->setPalette(palette);

Though it's not guaranteed to work on all platforms I think.

You could also create your own custom label widget instead of using QLabel,
if you really need to change the default look. I guess using <font
color="#00000">...</font> is also an option.

Hope that helps.

Elvis

> André
>
> Note: I did not check any of this in either docs or source code.
>
>
> Op 31/05/2016 om 10:55 schreef Berkay Elbir:
>
> Hello All,
>
> I have a problem about Qt Stylesheets. I use this code piece, this is a
> QLabel inside a QDialog.
>
> ui.newGroupNameLabel->setStyleSheet("QLabel { color : black; }");
>
> I also tried giving it a name usingQObject::setObjectName() and use an ID
> Selector to refer to it. But it still occurs.
>
> It affects whole project. I mean that affecting other widgets. All the
> expand symbols change to plus sign. This QLabel is unrelated to this
> widget(below).
> Did anyone face with this problem?
>
>
> [image: Inline image 1]
>
>
> [image: Inline image 2]
>
> Thanks in advance,
>
> Berkay
>
>
>
> _______________________________________________
> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160531/133a66d2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 807 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160531/133a66d2/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 1018 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160531/133a66d2/attachment-0001.png>


More information about the Interest mailing list