MCPcopy Index your code
hub / github.com/PyQt5/PyQt / drawControl

Method drawControl

QComboBox/Lib/CtComboBox.py:24–68  ·  view source on GitHub ↗
(self, element, option, painter, widget=None)

Source from the content-addressed store, hash-verified

22class ComboBoxStyle(QProxyStyle):
23
24 def drawControl(self, element, option, painter, widget=None):
25 if element == QProxyStyle.CE_ComboBoxLabel:
26 # https://github.com/qt/qtbase/blob/5.15.2/src/widgets/styles/qcommonstyle.cpp#L2200
27 editRect = self.subControlRect(QProxyStyle.CC_ComboBox, option,
28 QProxyStyle.SC_ComboBoxEditField,
29 widget)
30 painter.save()
31 painter.setClipRect(editRect)
32 if not option.currentIcon.isNull():
33 # 绘制图标
34 mode = QIcon.Normal if (
35 option.state &
36 QProxyStyle.State_Enabled) else QIcon.Disabled
37 pixmap = option.currentIcon.pixmap(
38 widget.window().windowHandle() if widget else None,
39 option.iconSize, mode)
40 iconRect = QRect(editRect)
41 iconRect.setWidth(option.iconSize.width() + 4)
42 iconRect = self.alignedRect(option.direction,
43 Qt.AlignLeft | Qt.AlignVCenter,
44 iconRect.size(), editRect)
45 if option.editable:
46 painter.fillRect(iconRect,
47 option.palette.brush(QPalette.Base))
48 self.drawItemPixmap(painter, iconRect, Qt.AlignCenter, pixmap)
49
50 if option.direction == Qt.RightToLeft:
51 editRect.translate(-4 - option.iconSize.width(), 0)
52 else:
53 editRect.translate(option.iconSize.width() + 4, 0)
54 if option.currentText and not option.editable:
55 # 考虑右边箭头位置
56 arrowRect = self.subControlRect(QProxyStyle.CC_ComboBox, option,
57 QProxyStyle.SC_ComboBoxArrow,
58 widget)
59 editRect.setWidth(editRect.width() + arrowRect.width())
60 # 绘制居中文字
61 self.drawItemText(
62 painter, editRect.adjusted(1, 0, -1, 0),
63 self.visualAlignment(option.direction, Qt.AlignCenter),
64 option.palette, option.state & QProxyStyle.State_Enabled,
65 option.currentText)
66 painter.restore()
67 return
68 super(ComboBoxStyle, self).drawControl(element, option, painter, widget)
69
70
71class CtComboBox(QComboBox):

Callers

nothing calls this directly

Calls 4

subControlRectMethod · 0.80
pixmapMethod · 0.80
restoreMethod · 0.80
widthMethod · 0.45

Tested by

no test coverage detected