QMainWindow无边框后,QMainWindow使用set.sheetStype()无法倒圆角!
直接上代码,新手作业,老手一看便知!
一,画window界面
#注意下面的QBitmap,QPainter两个库需从Pyside2引入
from PySide2.QtGui import QPixmap, QCloseEvent,QBitmap,QPainter
self.window = QMainWindow()
self.window.resize(430,330)
#界面居中
qRect = self.window.frameGeometry()
centerPoint = QDesktopWidget().availableGeometry().center()
qRect.moveCenter(centerPoint)
self.window.move(qRect.topLeft())
self.window.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint) #无边框
self.window.setStyleSheet('''
QMainWindow {background-color: white;}
''')
二,界面倒圆角
注意不要使用self.Painter.setRenderHint(QPainter.Antialiasing)功能
否则边角像素会成类似直角,而非标准弧角;
self.bmp = QBitmap(430,330) #这里将window size引入,否则无效果!
self.bmp.fill()
self.Painter = QPainter(self.bmp)
self.Painter.setPen(Qt.NoPen)
self.Painter.setBrush(Qt.black)
self.Painter.drawRoundedRect(self.bmp.rect(), 5, 5) #倒边角为5px
self.window.setMask(self.bmp) #切记将self.bmp Mark到window