📅  最后修改于: 2023-12-03 15:33:54.477000             🧑  作者: Mango
在PyQt5中,我们可以使用QLabel来创建任意形状的标签,包括圆形标签。下面是如何创建圆形标签的步骤。
from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QPainter, QColor, QBrush
class CircleLabel(QLabel):
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
brush = QBrush(QColor(255, 0, 0))
painter.setBrush(brush)
painter.drawEllipse(0, 0, self.width(), self.height())
circle_label = CircleLabel()
circle_label.setFixedSize(100, 100)
from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QPainter, QColor, QBrush
class CircleLabel(QLabel):
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
brush = QBrush(QColor(255, 0, 0))
painter.setBrush(brush)
painter.drawEllipse(0, 0, self.width(), self.height())
circle_label = CircleLabel()
circle_label.setFixedSize(100, 100)
现在,您已经了解了如何在PyQt5中创建圆形标签。使用这个简单的方法,您可以轻松地创建任意形状的标签,以满足您的UI设计需求。