我需要创建简单的模糊文本,并发现最简单的实现失败..只是无法得到原因?最简单的模式是:
from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
lbl = QtGui.QLabel()
lbl.setFont(QtGui.QFont('Arial', 100))
lbl.setText('Hello, World!')
effect = QtGui.QGraphicsBlurEffect()
effect.setBlurRadius(20)
lbl.setGraphicsEffect(effect)
lbl.show()
sys.exit(app.exec_())
但这只会产生黑色标签:
只有当我使用QMainWindow时,它才能按预期工作:
from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
win = QtGui.QMainWindow()
lbl = QtGui.QLabel()
win.setCentralWidget(lbl)
lbl.setFont(QtGui.QFont('Arial', 100))
lbl.setText('Hello, World!')
effect = QtGui.QGraphicsBlurEffect(lbl)
effect.setBlurRadius(20)
lbl.setGraphicsEffect(effect)
win.show()
sys.exit(app.exec_())
结果很好:
有什么区别?