如何在 PyQt 中创建不规则形状的窗口?
I found 这个C++解决方案 https://stackoverflow.com/questions/1333610/displaying-translucent-irregular-shaped-windows-with-qt,但是我不确定如何在 Python 中做到这一点。
干得好:
from PyQt4 import QtGui, QtWebKit
from PyQt4.QtCore import Qt, QSize
class RoundWindow(QtWebKit.QWebView):
def __init__(self):
super(RoundWindow, self).__init__()
self.initUI()
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
def sizeHint(self):
return QSize(300,300)
def paintEvent(self, event):
qp = QtGui.QPainter()
qp.begin(self)
qp.setRenderHint(QtGui.QPainter.Antialiasing);
qp.setPen(Qt.NoPen);
qp.setBrush(QtGui.QColor(255, 0, 0, 127));
qp.drawEllipse(0, 0, 300, 300);
qp.end()
a = QtGui.QApplication([])
rw = RoundWindow()
rw.show()
a.exec_()
截屏 https://i.stack.imgur.com/E21YG.png
我一生中从未编写过 C++,但阅读该代码示例并不难。您会发现大多数 Qt 在线文档都是用 C++ 编写的,因此至少能够阅读是很有用的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)