本文整理匯總了Python中PyQt5.Qt.QPen.setCapStyle方法的典型用法代碼示例。如果您正苦於以下問題:Python QPen.setCapStyle方法的具體用法?Python QPen.setCapStyle怎麽用?Python QPen.setCapStyle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.Qt.QPen
的用法示例。
在下文中一共展示了QPen.setCapStyle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: draw_snake_spinner
# 需要導入模塊: from PyQt5.Qt import QPen [as 別名]
# 或者: from PyQt5.Qt.QPen import setCapStyle [as 別名]
def draw_snake_spinner(painter, rect, angle, light, dark):
painter.setRenderHint(QPainter.Antialiasing)
if rect.width() > rect.height():
delta = (rect.width() - rect.height()) // 2
rect = rect.adjusted(delta, 0, -delta, 0)
elif rect.height() > rect.width():
delta = (rect.height() - rect.width()) // 2
rect = rect.adjusted(0, delta, 0, -delta)
disc_width = max(4, rect.width() // 10)
drawing_rect = QRect(rect.x() + disc_width, rect.y() + disc_width, rect.width() - 2 * disc_width, rect.height() - 2 *disc_width)
try:
angle_for_width = math.degrees(math.atan2(1.3 * disc_width, drawing_rect.width()))
except ZeroDivisionError:
angle_for_width = 5
gradient = QConicalGradient(drawing_rect.center(), angle - angle_for_width)
gradient.setColorAt(1, light)
gradient.setColorAt(0, dark)
painter.setPen(QPen(light, disc_width))
painter.drawArc(drawing_rect, 0, 360 * 16)
pen = QPen(QBrush(gradient), disc_width)
pen.setCapStyle(Qt.RoundCap)
painter.setPen(pen)
painter.drawArc(drawing_rect, angle * 16, (360 - 2 * angle_for_width) * 16)
示例2: draw_snake_spinner
# 需要導入模塊: from PyQt5.Qt import QPen [as 別名]
# 或者: from PyQt5.Qt.QPen import setCapStyle [as 別名]
def draw_snake_spinner(painter, rect, angle, light, dark):
painter.setRenderHint(QPainter.Antialiasing)
if rect.width() > rect.height():
delta = (rect.width() - rect.height()) // 2
rect = rect.adjusted(delta, 0, -delta, 0)
elif rect.height() > rect.width():
delta = (rect.height() - rect.width()) // 2
rect = rect.adjusted(0, delta, 0, -delta)
disc_width = max(3, min(rect.width() // 10, 8))
drawing_rect = QRect(rect.x() + disc_width, rect.y() + disc_width, rect.width() - 2 * disc_width, rect.height() - 2 *disc_width)
gap = 60 # degrees
gradient = QConicalGradient(drawing_rect.center(), angle - gap // 2)
gradient.setColorAt((360 - gap//2)/360.0, light)
gradient.setColorAt(0, dark)
pen = QPen(QBrush(gradient), disc_width)
pen.setCapStyle(Qt.RoundCap)
painter.setPen(pen)
painter.drawArc(drawing_rect, angle * 16, (360 - gap) * 16)