Pythin3.7 pyqt5 QCombobox で列を追加できずに悩んでいます。
やりたいことは
一列目:コード
二列目:名称
コンボボックスをクリックしたときの表示イメージ
0 オレンジ
1 りんご
2 メロン
1列目はコード、2列目は名称を表示したいです。
Pythonで記述する場合の方法をご教授お願い致します。
sample.py
python
1import os 2import sys 3from PyQt5 import QtCore, QtGui, QtWidgets, uic 4 5class Ui_sample(QtWidgets.QMainWindow): 6 7 def __init__(self, parent=None): 8 super(Ui_sample, self).__init__(parent) 9 uic.loadUi('sample.ui', self) 10 self.comboBox.addItem("0") 11 self.comboBox.addItem("1") 12 self.comboBox.addItem("2") 13 14 15if __name__ == '__main__': 16 rowCnt = 0 17 app = QtWidgets.QApplication(sys.argv) 18 ui = Ui_sample() 19 ui.show() 20 21 sys.exit(app.exec_())
sample.ui
python
1<?xml version="1.0" encoding="UTF-8"?> 2<ui version="4.0"> 3 <class>Form</class> 4 <widget class="QWidget" name="Form"> 5 <property name="geometry"> 6 <rect> 7 <x>0</x> 8 <y>0</y> 9 <width>174</width> 10 <height>176</height> 11 </rect> 12 </property> 13 <property name="windowTitle"> 14 <string>Form</string> 15 </property> 16 <widget class="QComboBox" name="comboBox"> 17 <property name="geometry"> 18 <rect> 19 <x>50</x> 20 <y>40</y> 21 <width>80</width> 22 <height>22</height> 23 </rect> 24 </property> 25 </widget> 26 </widget> 27 <resources/> 28 <connections/> 29 <slots> 30 <signal>signal1()</signal> 31 </slots> 32</ui> 33
あなたの回答
tips
プレビュー