PyQt创建带阴影的窗口
from PyQt5.Qt import *
import sys
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground, True)
height = 300
width = 500
padding = 20
self.setFixedSize(width+2*padding, height+2*padding)
self.center_widget = QWidget(self)
self.center_widget.setGeometry(padding, padding, width, height)
self.setAccessibleName('center-widget')
self.center_widget.setAttribute(Qt.WA_StyledBackground, True)
self.center_widget.setStyleSheet('QWidget{background-color: rgba(255, 255, 255, 1); border-radius:8px}')
shadow_effect = QGraphicsDropShadowEffect(self.center_widget)
shadow_effect.setOffset(0, 0)
shadow_effect.setColor(Qt.gray)
shadow_effect.setBlurRadius(10)
self.center_widget.setGraphicsEffect(shadow_effect)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())