20

更新

有关使用 Qt 和DWM的示例,请参阅在 Windows 上使用模糊替代文字 http://labs.trolltech.com/blogs/wp-content/uploads/2009/09/blurbehind2.png


原始问题:

我想用 Qt 创建一个 Windows Aero Glass 窗口,现在它看起来像这样: 替代文字

但是在调用了一些之后,my_window->repaint()我的窗口标签就坏了: 替代文字

但现在如果我稍微调整窗口大小,它会正确重绘。


问题是:我如何擦除窗口背景,以便小部件将自己绘制在干净的玻璃上?


重现问题的简短代码是(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几次。

无论如何,使用带有 Aero Glass 的标签不是我需要的,因为 QLabel 不知道如何用一段时间发光(如窗口的标题)来绘制自己。我需要的是一种清洁“玻璃”的通用方法。

4

2 回答 2

6

只需使用:

QPainter p

p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(boundsRect, QColor(0, 0, 0, 0));

这将丢弃旧内容并用透明颜色填充。

更多信息在

编辑:最好使用 CompositionMode_Clear 并用任何颜色绘制矩形。

于 2009-01-27T19:40:01.127 回答
1

我已经在谷歌上搜索了一段时间,所以我想我会分享解决方案:

将 WA_NoSystemBackground 替换为 WA_TranslucentBackground 并忘记 mousepressevent

现在窗户是透明的航空玻璃,并在需要时自动重新渲染,耶 :)

于 2011-08-16T10:55:43.067 回答