Qt:擦除背景(Windows Aero Glass) [英] Qt: Erase background (Windows Aero Glass)
问题描述
请参见在Windows上使用模糊有关使用Qt和.替代文字http://labs. trolltech.com/blogs/wp-content/uploads/2009/09/blurbehind2.png
see Using Blur Behind on Windows for an example of using Qt and DWM.alt text http://labs.trolltech.com/blogs/wp-content/uploads/2009/09/blurbehind2.png
我想用Qt创建一个Windows Aero Glass窗口,现在看起来像这样:
I want to create a Windows Aero Glass window with Qt, now it looks like this:
但是在调用某些my_window->repaint()
之后,我的窗口的标签坏了:
But after calling some my_window->repaint()
my window's label becomes broken:
但是现在如果我稍微调整窗口大小,它将正确地重新绘制.
But now if I resize the window slightly, it repaints properly.
问题是:我如何擦除窗口背景,以便小部件可以在干净的玻璃上绘画自己?
The question is: how do I erase the window background, so that widgets would paint themselves on a clean glass?
重现此问题的简短代码是(带有Aero的Vista):
The short code to reproduce the problem is (Vista with Aero):
class Window(QWidget):
def __init__(self, *args):
QWidget.__init__(self, *args)
self.setLayout(QVBoxLayout())
self.layout().addWidget(QLabel("This is the text"))
# let the whole window be a glass
self.setAttribute(Qt.WA_NoSystemBackground)
from ctypes import windll, c_int, byref
windll.dwmapi.DwmExtendFrameIntoClientArea(c_int(self.winId()), byref(c_int(-1)))
def mousePressEvent(self, event):
self.repaint()
您现在可以单击窗口,或者只需按几次Alt-Tab
.
You can click the window now, or just hit Alt-Tab
several times.
无论如何,我不需要在Aero Glass上使用标签,因为QLabel不知道如何用一会儿辉光(例如窗口的标题)进行绘制.我需要的是一种清洁玻璃杯"的一般方法.
Anyway, using labels with Aero Glass is not what I need, because QLabel doesn't know how to paint itself with a while glow (like the title of the window). What I need is a general way to clean the "glass".
推荐答案
只需使用:
QPainter p
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(boundsRect, QColor(0, 0, 0, 0));
这将丢弃旧内容并以透明颜色填充.
This discards the old contents and fills with transparent color.
更多信息,在
-
http://techbase.kde .org/Development/Tutorials/Graphics/Performance#QPixmap :: setAlphaChannel.28.29
http://doc.qt.digia.com/qtjambi-4.4/html/com/trolltech/qt/gui/QPainter.CompositionMode.html
最好使用CompositionMode_Clear并用任何颜色绘制矩形.
Better use CompositionMode_Clear and paint the rect with whatever color.
这篇关于Qt:擦除背景(Windows Aero Glass)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!