Transluscent background of a QLabel in a QDialog. Qt 4.8.4
-
Hello,
there is a modal frameless dialog with the whole screen geometry. It has a contant QPixmap on its background which it draws constantly in paintEvent.
Inside the class there is rubber band drawer which inherits a QLabel (the whole screen geometry) which draws constantly a region defined by a set of elastic rectangles.
Since in Qt 4.8 the contents propagation is the default behavior it should stay as it is. The only thing to add is
setAttribute(Qt::WA_TranslucentBackground); to the rubber band drawer constructor. However, when the dialog is shown the QLabel background(rubber band drawer) is not transluscent. After I changed drawing of the pixmap in the dialog by making the pixmap transparent
@void dialog::mk_transparent_pixmap()
{
pixmap = QPixmap(trigger_path).scaled(size());
// Create new picture for transparent
QPixmap transparent(pixmap.size());// Do transparency transparent.fill(Qt::transparent); QPainter p(&transparent); p.setCompositionMode(QPainter::CompositionMode_Source); p.drawPixmap(0, 0, pixmap); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); // Set transparency level to 150 (possible values are 0-255) // The alpha channel of a color specifies the transparency effect, // 0 represents a fully transparent color, while 255 represents // a fully opaque color. p.fillRect(transparent.rect(), QColor(0, 0, 0, 180)); p.end(); // Set original picture's reference to new transparent one pixmap = transparent;
}
void dialog::draw_trigger()
{
if ( !is_transparent ) mk_transparent_pixmap(), is_transparent = true;
QPainter painter(this);
painter.drawPixmap(0,0,pixmap);
}@
it worked. Sure, since it is transparent.
But how to achieve the goal in other ways? Making another modal dialog with transluscent background? -
have you tried the rubber band widget (QLabel) autoFillBackground to true?
-
When autoFillBackground is set to true and transluscent background is false it's of gray color. When the transluscent background is turned on it's of black color. Also black transparent (alpha=0) palette is used for an active window.
-
bq. When autoFillBackground is set to true and transluscent background is false it’s of gray color.
this should be ok, and use: setStyleSheet("background:transparent")