반응형
/*********************************************************************************************************
-- Title : [PyQt4] Listview mutiselection 및 Combobox,, Treeview, Tableview 구현
-- Reference : http://stackoverflow.com/
-- Key word : python pyqt pyqt4 qt qt4 파이썬 리스트, 콤보, 트리, 테이블 listview combobox treeview tableview
리스트뷰 콤보박스 트리뷰 테이블뷰 qlistview qcombobox qtreeview qtableview
*********************************************************************************************************/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, QtCore class Window(QtGui.QMainWindow): def __init__(self): super(Window, self).__init__() self.setFixedSize(600, 400) self.setWindowTitle("Test listview, combobox, treeview, tableview with model") QtGui.QApplication.setStyle("windows") # input data vData = QtCore.QStringList() vData << "one" << "two" << "three" << "four" << "five" vData.append(QtCore.QString("six")) vData.append(QtCore.QString("seven")) # define model object self.tModel = QtGui.QStringListModel(vData) # -- create listview object ---------------------------- tLabel = QtGui.QLabel(self) tLabel.move(30,15) tLabel.setText("Listview") self.tListview = QtGui.QListView(self) self.tListview.move(30, 40) self.tListview.resize(100, 80) self.tListview.setModel(self.tModel) self.tListview.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) # set multi selection self.tListview.clicked.connect(self.on_listview) # -- create combobox object ---------------------------- tLabel2 = QtGui.QLabel(self) tLabel2.move(150, 15) tLabel2.setText("Combobox") self.tCombobox = QtGui.QComboBox(self) self.tCombobox.setModel(self.tModel) self.tCombobox.move(150, 40) self.tCombobox.resize(100, 22) self.tCombobox.currentIndexChanged.connect(self.on_combobox) # -- create treeview object ---------------------------- tLabel3 = QtGui.QLabel(self) tLabel3.move(270, 15) tLabel3.setText("Treeview") self.tTreeview = QtGui.QTreeView(self) self.tTreeview.setModel(self.tModel) self.tTreeview.move(270, 40) self.tTreeview.resize(100, 200) self.tTreeview.clicked.connect(self.on_treeview) # -- create tableview object --------------------------- tLabel4 = QtGui.QLabel(self) tLabel4.move(390, 15) tLabel4.setText("Tableview") self.tTableview = QtGui.QTableView(self) self.tTableview.setModel(self.tModel) self.tTableview.move(390, 40) self.tTableview.resize(100, 200) self.tTableview.clicked.connect(self.on_tableview) # -- create textbox object ----------------------------- self.tTextbox = QtGui.QLineEdit(self) self.tTextbox.move(30, 300) self.tTextbox.resize(340, 22) # -- define action ----------------------------------------- def on_tableview(self, index): vSeq = index.row() vData = index.data().toString() self.tTextbox.setText("TableView list: '" + vData + "' (" + str(vSeq) + " index)") def on_treeview(self, index): vSeq = index.row() vData = index.data().toString() self.tTextbox.setText("TreeView list: '" + vData + "' (" + str(vSeq) + " index)") def on_listview(self, index): vSeq = index.row() vData = index.data().toString() self.tTextbox.setText("ListView list: '" + vData + "' (" + str(vSeq) + " index)") def on_combobox(self, index): vSeq = self.tCombobox.currentIndex() vData = self.tCombobox.currentText() self.tTextbox.setText("ComboBox : '" + vData + "' (" + str(vSeq) + " index)") if __name__ == "__main__": app = QtGui.QApplication(sys.argv) gui = Window() gui.show() sys.exit(app.exec_()) | cs |
반응형