[Python] PyQT4 ComboBox와 TableWidget 제어
by 담배맛구마
ComboBox
#Add ComboBox
self.cbTime = QtGui.QcomboBox(MainObject)
#Set Geometry
self.cbTime.setGeometry(QtCore.QRect(x, y, w, h))
#Add Item
self.cbTime.addItem("01:00")
self.cbTime.addItem("03:00")
self.cbTime.addItem("05:00")
...
#Align Center
self.cbTime.setEditable(True)
self.cbTime.lineEdit().setReadOnly(True)
self.cbTime.setAlignment(QtCore.Qt.AlignCenter)
#Get Current Selected Item
self.cbTime.currentText()
TableWidget
#Add TableWidget
self.tbTimeTable = QtGui.QTableWidget(MainObject)
#Set Geometry
self.tbTimeTable.setGeometry(QtCore.QRect(x, y, w, h))
#Init Column/Row Count(Assume that table is 3 x 3 Table)
self.tbTimeTable.setColumnCount(3)
self.tbTimeTable.setRowCount(3)
#Set Column And Column Name(Assume that table is 3 x 3 Table)
self.tbTimeTable.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem())
self.tbTimeTable.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem())
self.tbTimeTable.setHorizontalHeaderItem(2, QtGui.QTableWidgetItem())
setHorizontalHeaderItem(0, item).setText("No1")
setHorizontalHeaderItem(1, item).setText("No2")
setHorizontalHeaderItem(2, item).setText("No3")
#Insert Item to Table(Assume that table is 3 x 3 Table)
dataLst = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
for row in dataLst:
rowPosition = self.tbTimeTable.rowCount() #Get Row Count(This Value is "Current Row Count + 1")
self.tbTimeTable.insertRow(rowPosition) # Insert New Row
self.tbTimeTable.setItem(rowPosition , 1, row[0])
self.tbTimeTable.setItem(rowPosition , 2, row[1])
self.tbTimeTable.setItem(rowPosition , 3, row[2])
#Init Table Data
self.tbTimeTable.setRowCount(0)
#Resize Column/Row Size
self.tbTimeTable.resizeColumnsToContents()
self.tbTimeTable.resizeRowsToContents()
#Set Background Color
self.tbTimeTable.item(ROWPOSITION , COLUMNPOSITION).setBackground(QtGui.QColor(R, G, B))
반응형
'Dev-' 카테고리의 다른 글
[Python] 나름대로 만들어본 PyV8를 이용한 악성스크립트 분석 (0) | 2016.07.17 |
---|---|
[Python] Geoip를 통한 IP 별 국가코드 매칭 (2) | 2016.07.09 |
[Python] Send Mail by my gmail account (0) | 2016.01.10 |
[Python] PyQT5 기본템플릿비교(Widget, Dialog, Main Window) (0) | 2015.11.14 |
[Python] PyQT5 시작하기 (6) | 2015.10.26 |
블로그의 정보
정윤상이다.
담배맛구마