PDA

View Full Version : QGroupBox image in title



friendofgermany
26th July 2011, 13:30
Hey Guys,

I'm trying to style my QGroupBox a little.
What I've done yet:



QGroupBox {

background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E0E0E0, stop: 1 #FFFFFF);
border: 2px solid rgb(66, 66, 66);
border-top: 30px solid rgb(66, 66, 66);


border-bottom-right-radius: 20px;
border-bottom-left-radius: 20px;
margin-top: 0ex; /* leave space at the top for the title */
font-weight: bold;
}

QGroupBox::title {

subcontrol-origin: margin;
subcontrol-position: top left; /* position at the top center */

background-color: rgb(66, 66, 66);
color: rgb(255, 255, 255);
padding: 8 10px;
}


That looks good for me, but what i would like to have is an image left of the title.
Any ideas how to do that?

Thanks in advance.

LG from germany

high_flyer
27th July 2011, 14:12
AFAIK, you can't since QGroupBox exposes the title as QString (even if internally its probably a QLabel).
You can try to "cheat", by setting a background image for the titles, which will be as wide as the string + the image you want to have, but will depict the image you want only on the right side, and the rest fill with transparent or background color, so that the title string will be visible on top of it.
If this doesn't work, you will probably have to subclass QGroupBox.