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
| from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self, rows, columns):
QtGui.QWidget.__init__(self)
self.table = QtGui.QTableWidget(rows, columns, self)
for column in range(columns):
for row in range(rows):
item = QtGui.QComboBox()
if column != 0:
item = QtGui.QTableWidgetItem('Text%d' % row)
self.table.setItem(row, column, item)
else:
item = QtGui.QComboBox()
self.table.setCellWidget(row, column, item)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.table)
self.table.setMouseTracking(True)
self.table.cellEntered.connect(self.handleItemEntered)
def handleItemEntered(self):
print 'cell'
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window(6, 3)
window.setGeometry(500, 300, 350, 250)
window.show()
sys.exit(app.exec_()) |
Partager