[Qt-interest] Skins and Style Sheets

Bo Thorsen bo at fioniasoftware.dk
Tue May 17 08:08:02 CEST 2011


Den 17-05-2011 03:49, Darryl Hunter skrev:
> Hi all,
>
> I’m adding functionality into a VB6 application, but want to add it
> using Qt. Makes things run a lot faster, and, hey, it’s using Qt instead
> of VB so it **has** to be better J.
>
> The VB6 application uses SkinCrafter to create skins, and I need my Qt
> component to use these too. But from what I understand
> (http://lists.trolltech.com/qt-interest/2006-09/thread01024-0.html),
> this isn’t possible, so I need to convert them to a stylesheet.
>
> The problem I’m getting is that I need to set the 8 border image
> components (top-left, top-centre, top-right, centre-left, centre-right,
> bottom-left, bottom-centre and bottom-right) of a QDialog. This doesn’t
> seem to be working for me.
>
> I found http://www.qtcentre.org/archive/index.php/t-25974.html which was
> needed for me to actually set border-image on the title section of the
> QDialog, but I was unable to set the corner images. Obviously one option
> is to do more work in paintEvent, but if anybody has done this before,
> any suggestions would be greatly appreciated.

This is working code from one of my current projects:

QPushButton {
	background:none;
	border-image: url(images/add_comment_bt.png) 8 8 8 8;
	margin: 0px;
	border-top: 8px transparent;
	border-bottom: 8px transparent;
	border-right: 8px transparent;
	border-left: 8px transparent;
	font: bold "Tahoma";
}

QPushButton:pressed {
	border-image: url(images/add_comment_bt_pressed.png)  8 8 8 8;
}

I think it's very odd that the transparent lines are necessary, but it's 
the only way I can make this work.

> Otherwise I’ll have to write the UI in VB, and I really don’t want to
> have to do that…

You are probably not going to be able to just make a one-to-one 
transformation to Qt stylesheets. I always find the stylesheets to lack 
parts of what I need to do. Then you can either make a QStyle subclass 
or start implementing paintEvent() or change the way the style option 
objects are initiated or... There are many tricks you can do. But you 
have to expect that some of what you can do in VB won't be possible in 
Qt stylesheets. Just as the reverse is true.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list