没有QMainWindow,为什么PyQt效果不起作用?

时间:2015-12-18 11:12:01

标签: python pyqt

我需要创建简单的模糊文本,并发现最简单的实现失败..只是无法得到原因?最简单的模式是:

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_())

但这只会产生黑色标签:

enter image description here

只有当我使用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_())

结果很好:

enter image description here

有什么区别?

0 个答案:

没有答案