pyqt6QComboBox字体居中
时间: 2024-06-05 13:04:26 浏览: 178
PyQt6中的QComboBox可以通过设置样式表来实现字体居中,具体方法如下:
```
combo_box.setStyleSheet("QComboBox { font-size: 12px; } QComboBox::item { height: 30px; } QComboBox::item:selected { background-color: lightgray; } QComboBox::item:selected:active { background-color: gray; } QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 30px; border-left-width: 1px; border-left-color: darkgray; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } QComboBox::down-arrow { image: url(down_arrow.png); width: 16px; height: 16px; } QComboBox::down-arrow:on { image: url(up_arrow.png); } QListView { font-size: 12px; background-color: white; } QListView::item { height: 30px; } QListView::item:selected { background-color: lightgray; } ")
combo_box.setEditable(True)
combo_box.lineEdit().setAlignment(Qt.AlignCenter)
```
其中,combo_box是一个QComboBox对象,`combo_box.lineEdit().setAlignment(Qt.AlignCenter)`即可将下拉框中的文本居中显示。
阅读全文