QTextEdit with semi-transparent background
I have the following code to paint a semi-transparent label on an image and then write on that label:
Code:
// topLabel->setAttribute(Qt::WA_NoSystemBackground);
// a white semi-transparent background
topLabel->setPalette(palette);
topLabel->setText(*text);
It creates a white, opaque background.
It topLabel is QLabel, it creates a transparent background.
In any case, it is not semi-transparent.
Re: QTextEdit with semi-transparent background
Quote:
I have the following code to paint a semi-transparent label on an image and then write on that label
I don't quite understand what you mean? A transparent label background?
Why don't you do this in the paintEvent of your label? Fill it with a semitransparent pixmap, and then draw on it whatever you want...
Regards.
Re: QTextEdit with semi-transparent background
I mean a semi-transparent label background -- i.e. 50% white, 50% transparent.
According to the QWidget doc, "The background can be set using ... setPalette()."
So I'm hoping to avoid subclassing QStyle.
The size of the background can be changed, so a semi-transparent pixmap won't work.
Re: QTextEdit with semi-transparent background
You can always scale the pixmap, being transparent and all... And I didn't mean subclassing QStyle, but QLabel. I have tried this method before, and it works.
Re: QTextEdit with semi-transparent background
Since it is only SEMI-transparent (that is, partially opaqe), scaling will give bad resolution.
Well, true that you can use a huge-huge pixmap and scale it down, but that's not very efficient.
Re: QTextEdit with semi-transparent background
Transparent pixmap, means only alpha channel, so no scaling effects occur.
Is this what you're trying to achieve?
Code:
{
pix.fill( Qt::transparent );
p.drawPixmap( rect(), pix );
p.setOpacity( 0.5 );
p.fillRect( rect(), Qt::white );
p.setOpacity( 1 );
p.drawText( rect(), "test" );
};
I get a white label, 50% opaque, with some text on it.
Re: QTextEdit with semi-transparent background
Quote:
Originally Posted by
ber_44
Shouldn't that be QPalette::Base: "Used as the background color for text entry widgets; usually white or another light color"?