在Windows上应用QML效果

时间:2016-06-13 15:59:04

标签: python pyqt qml

我有一段代码可以创建一个带有图像的简单Frameless窗口,我想在帧上应用一些QML效果(DropShadow效果和高斯模糊)而不是图像,我该如何实现呢?

# !/usr/bin/env python
# -*- coding: UTF-8 -*-

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt


class Frame(QtWidgets.QFrame):
    def __init__(self, width, height, parent=None):
        super(Frame, self).__init__(parent)

        self.setWindowFlags(Qt.FramelessWindowHint)

        self.setFixedSize(width, height)

        self.setStyleSheet("""
        image: url("images/img.jpg") 0 0 0 0 stretch stretch;""")

    def mousePressEvent(self, event):
        self.offset = event.pos()
        self.pressed = 1

    def mouseMoveEvent(self, event):
        if self.pressed:
            x = event.globalX()
            y = event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x - x_w, y - y_w)

    def mouseReleaseEvent(self, event):
        self.pressed = 0

if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    c = Frame(width=450, height=255)
    c.show()
    app.exec_()

0 个答案:

没有答案