| 69 | |
| 70 | |
| 71 | class CtComboBox(QComboBox): |
| 72 | |
| 73 | def __init__(self, *args, **kwargs): |
| 74 | super(CtComboBox, self).__init__(*args, **kwargs) |
| 75 | # 绑定每个元素添加信号,用于设置文本居中 |
| 76 | self.model().rowsInserted.connect(self._onRowsInserted) |
| 77 | self.setStyle(ComboBoxStyle()) |
| 78 | |
| 79 | def _onRowsInserted(self, index, first, last): |
| 80 | if first < 0: |
| 81 | return |
| 82 | for i in range(first, last + 1): |
| 83 | self.view().model().item(i).setTextAlignment(Qt.AlignCenter) |