其他分享
首页 > 其他分享> > PyQt5中QComboBox文字和下拉项右对齐显示

PyQt5中QComboBox文字和下拉项右对齐显示

作者:互联网

 


 

from PyQt5.QtWidgets import QComboBox, QLineEdit, QListWidget, QCheckBox, QListWidgetItem
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
import sys

class MyQComboBox(QComboBox):
    def __init__(self, items):  # items==[str,str...]
        super().__init__()

        le = QLineEdit()        #显示框右对齐
        le.setAlignment(Qt.AlignRight)
        le.setReadOnly(True)
        super().setLineEdit(le)

        listWgt = QListWidget() #列表框右对齐
        for item in items:
            listWgtItem = QListWidgetItem(item)
            listWgtItem.setTextAlignment(Qt.AlignRight)
            listWgt.addItem(listWgtItem)
        super().setModel(listWgt.model())
        super().setView(listWgt)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myCmb = MyQComboBox(['11','222','333','4444','55555'])
    myCmb.show()
    sys.exit(app.exec_())

参考链接:https://blog.csdn.net/qq_34305316/article/details/96488636 

 

 

  

标签:__,下拉项,le,QComboBox,PyQt5,listWgt,import,super
来源: https://www.cnblogs.com/wangmantou/p/14499455.html