PDA

View Full Version : Another Question with StyleSheets



daiheitan
12th March 2010, 03:34
I am now trying to allow users change the app's theme.A theme contains some PNG files and related *.qss files.
The app will Open the current theme folder and read the correct QSS file to set styles for widgets.
Now problem comes:
In the QSS file ,my image URL use relative paths(That's a must,as theme designers can't get the path of the theme folder,so absolute path can not be used.)
However,QT does not search for files in the QSS's folder ,but still search in the App's folder.So the resource files always can't be loaded.
That really blocks me.

Any reply,thanls

zgulser
12th March 2010, 07:40
Once I faced this problem and solved it by using setPixmap("../user/yourfile.PNG"); from the source code.

Lykurg
12th March 2010, 08:03
A nice solution I use is: Everywhere you need the path to the folder write "%PATH%" (or something else) and when you chance your qss file, read all qss in a string, determinate the path to your qss folder at runtime (since it could be different on different platforms) and do a simple QString::replace() befor setting the qss.

daiheitan
12th March 2010, 08:58
Thanks.In fact just a few minutes ago I solved this problem just like Lykurg did.I read the file into a QString and replaced all "url(./" to absolute Path.

Another question:
In Windows vista&7, the maximize,minimize and close button are put in a line and there 's no space between them.But when one button is hovered, the button has shadow.The most important is :the shadow is partly on the other buttons.
http://photo2.bababian.com/upload3/20100312/50C3A651B9C039EB88B453A6ED886586.jpg
In Qt,a QPushButton could also look different by using a PNG file(e.g: a shadow Button) as backgound-image when hovered.But,two widgets could not overlap each other.
I wonder how to do it in Qt to create a group of vista-like buttons.

Or anyone know how to create a Google Chrome-style UI?(No titleBar But has the windows control Buttons)?
Still, waiting online for any reply.

Lykurg
12th March 2010, 10:02
I would create a custom widget, handling all "buttons", and implement mouse press/release and do the drawing myself. (To detect hover use mouse move event)

daiheitan
12th March 2010, 11:43
I just find QML,but not know that very much.
Could QML handle this?

Lykurg
12th March 2010, 11:48
Sure it can, but it is also not that easy and you have to wait till summer when the stable version is shipped out. And as I understand the whole concept it is primary for interfaces with fixed sizes ==> mobile embedded devices...

daiheitan
12th March 2010, 12:29
oops...
I just tried Qt creator 2.0 Alpha,and it crashes a lot. Especially when using the Designer For QML.

One more problem is (though I asked it in another post,but no good answer)
Most programs use PNG file for buttons.And images of hover, normal,pressed states of a button are in just one PNG file.
I wonder if there is a way in Qt style sheet to use a part of a PNG file.
(I really wish there would be a way.....)