PDA

View Full Version : don't work qlineargradient for text in QLabel



GreenScape
27th July 2010, 00:36
i tried everything. in QtDesigner, gradient for QLabel works perfectly, but when i setting style sheet like this :
"* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"

dynamically in my code, i have a white text on my label :mad:
what am i do wrong?

here, how i do this:


mpExampleLabel = new QLabel(tr("Cell text example"), this);
mpExampleLabel->setFrameStyle(QFrame::Box);
mpExampleLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
mpExampleLabel->setStyleSheet("* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));");

norobro
27th July 2010, 06:15
Looks like you are missing a closing brace in your setStyleSheet statement.

Lykurg
27th July 2010, 07:44
You can also try to skip the "* {".

GreenScape
27th July 2010, 09:09
no, this is just example, i copied style from QtDesigner and loose brace pasting into browser

as i said, i tried everything, without selector (i. e. without "* {" and "}"), with "QLabel" and "*".

here, compilable example:

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QLabel mpExampleLabel("Cell text example");
mpExampleLabel.setFrameStyle(QFrame::Box);
mpExampleLabel.setAlignment(Qt::AlignHCenter|Qt::A lignVCenter);
mpExampleLabel.setStyleSheet("* {color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));}");
mpExampleLabel.show();
return app.exec();
}

i always have a label with white text! (i. e. text color will be always the color of last stop of any gradient). what am i do wrong?

GreenScape
27th July 2010, 10:29
i exeperimented with styles and found interesting stuff:

when i replace

color: qlineargradient(spreadad, x1:0 y1:0, x2:1 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
with

color: qlineargradient(spreadad, x1:0 y1:0, x2:100 y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
label's text filled with gradient starts from (0,0) to (100,0), this seems to be bug? values after x1,x2,y1,y2 means proportion of widget but not concrete width/height! x2:1 always means x2=width()*1 but not just one pixel (x==1) same gradient for background-color works perfectly(i. e. x2=width()*1).

Lykurg
27th July 2010, 10:37
No it is not a bug. You can specify if your given coordinates should be treated absolut or streched to the actual painting area. I'd suggest also to skip the first option. Then by default it is streched to the painting area.

GreenScape
27th July 2010, 11:08
what first option? spread:pad? how can i specify?

and why absolutely the same style sheet string for background-color works relatively, but for color - absolutely?

GreenScape
29th July 2010, 17:59
No it is not a bug. You can specify if your given coordinates should be treated absolut or streched to the actual painting area. I'd suggest also to skip the first option. Then by default it is streched to the painting area.

HOW can i specify, man!?