PDA

View Full Version : [QT Ctrator] Setting StyleSheeet in code



Tomasz
26th January 2011, 11:03
Hello!

I've got a little problem with setting style sheet in my code:



this->setStyleSheet(QString("QCheckBox::indicator:unchecked {image: url("APP_PATH"\"/grafqtch/uncheckedbig.png\");}"));
this->setStyleSheet(QString("QCheckBox::indicator:checked {image: url("APP_PATH"\"/grafqtch/checkedbig.png\");}"));


APP_PATH is a definition with a prefix of my application path (in configuration header file). I want all QCheckBox to have this style. When I put this in graphic editor in style sheet section of my form (without APP_PATH) it works fine but with that path also have problems. Can I somehow use header configuration file while I'm designing form in graphic mode? Or maybe I can set that stylesheet in code in a different way?

thanks in advance
best regards
Tomasz

Lykurg
26th January 2011, 11:17
Have a look on how to concat QString: QString::arg() or QString::operator+=.

Tomasz
26th January 2011, 11:22
Yes, You're right. I've fixed it, and now It works in my code. But one more problem. Can I 'append' somehow my stylesheet? When I set first one, and then the second one in code - only last one works. Is there any other way than crating long QString with all style?

thanks in advance
best regards
Tomasz

Lykurg
26th January 2011, 11:25
Of course only the last one works because setStyleSheet deletes all previous set ones. Simple create one "big" QString using the mentioned += operator and set all at once.
QString css;
css += "foo";
css += "bar";
setStyleSheet(css);

Or use QString::append().

Tomasz
26th January 2011, 11:59
Thanks! But I thought that maybe there is simpler way to change style, than create one big QString. Thought that each property is treated separately, and I can change just one of it somehow.

thanks
best regards
Tomasz