问题
Update
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
Original question:
I want to create a Windows Aero Glass window with Qt, now it looks like this:
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?
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()
You can click the window now, or just hit Alt-Tab
several times.
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".
回答1:
Just use:
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.
More info at
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
Edit: Better use CompositionMode_Clear and paint the rect with whatever color.
回答2:
I've been googling for a while so I thought I would share the solution:
replace WA_NoSystemBackground to WA_TranslucentBackground and forget about the mousepressevent
now the window is transparent aero glass and re-rendered automatically when needed, yay :)
来源:https://stackoverflow.com/questions/453069/qt-erase-background-windows-aero-glass