반응형
/*********************************************************************************************************
-- Title : [PyQt4] Tables, Tooltip 구현
-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui tables tooltip 테이블 툴팁
*********************************************************************************************************/
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
# ------------------------------------------
# -- Create window
# ------------------------------------------
myApp = QApplication(sys.argv) # Create an PyQT4 application object.
table = QTableWidget()
tableitem = QTableWidgetItem()
table.setWindowTitle("QTableWidget Example @pythonspot.com")
table.resize(300, 250)
table.setRowCount(6)
table.setColumnCount(2)
# ------------------------------------------
# -- Set label
# ------------------------------------------
table.setHorizontalHeaderLabels(("H1;H2;").split(";"))
table.setVerticalHeaderLabels(("V1;V2;V3;V4;V5;V6").split(";"))
# ------------------------------------------
# -- Set data
# ------------------------------------------
table.setItem(0, 0, QTableWidgetItem("Item (0,0)"))
table.setItem(0, 1, QTableWidgetItem("Item (0,1)"))
table.setItem(1, 0, QTableWidgetItem("Item (1,0)"))
table.setItem(1, 1, QTableWidgetItem("Item (1,1)"))
table.setItem(2, 0, QTableWidgetItem("Item (2,0)"))
table.setItem(2, 1, QTableWidgetItem("Item (2,1)"))
table.setItem(3, 0, QTableWidgetItem("Item (3,0)"))
table.setItem(3, 1, QTableWidgetItem("Item (3,1)"))
table.setItem(4, 0, QTableWidgetItem("Item (4,0)"))
table.setItem(4, 1, QTableWidgetItem("Item (4,1)"))
table.setItem(5, 0, QTableWidgetItem("Item (5,0)"))
table.setItem(5, 1, QTableWidgetItem("Item (5,1)"))
# ------------------------------------------
# -- Set tooltip
# ------------------------------------------
table.horizontalHeaderItem(0).setToolTip("Column 1")
table.horizontalHeaderItem(1).setToolTip("Column 2")
# ------------------------------------------
# -- Create the actions
# ------------------------------------------
def on_cellclick(row,col):
print "Clicked on " + str(row) + " " + str(col)
# ------------------------------------------
# -- Connect the signals to the slots
# ------------------------------------------
table.cellClicked.connect(on_cellclick)
# ------------------------------------------
# -- Show the window and run the app
# ------------------------------------------
table.show()
myApp.exec_()
반응형