[英]How to center text in QComboBox?
我尝试过使用QComboBox的模型()并没有取得明显的成功。 我想知道是否可以在QCombobox的中心对齐文本。 除了文本对齐外,似乎项目的字体不受更改其PointSize的影响....
combo=QtGui.QComboBox()
comboModel=combo.model()
for name in ['one','two','three']:
item = QtGui.QStandardItem(name)
itemFont = item.font()
itemFont.setPointSize(8)
item.setFont(itemFont)
# item.setAlignment(QtCore.Qt.AlignCenter)
comboModel.appendRow(item)
您可以使用setAlignment
方法:
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
layout = QtGui.QVBoxLayout(self)
self.combo = QtGui.QComboBox()
self.combo.setEditable(True)
self.combo.lineEdit().setAlignment(QtCore.Qt.AlignCenter)
self.combo.addItems('One Two Three Four Five'.split())
layout.addWidget(self.combo)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.