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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class PlanningTable(QtGui.QTableWidget):
def __init__(self, parent):
QtGui.QTableWidget.__init__(self, parent)
self.clicked.connect(self.on_cell_clicked)
#
def mousePressEvent(self, event):
self.clicked_at = event.pos()
QtGui.QTableView.mousePressEvent(self, event)
#
def on_cell_clicked(self, idx):
col = idx.column()
row = idx.row()
clicx = self.clicked_at.x()
col_begin = self.columnViewportPosition(col)
col_end = col_begin + self.columnWidth(col)
print 'Clicked column:', col, "row:", row
print 'Bord gauche:', col_begin, 'bord droit:', col_end
print 'clic x: ', clicx
if clicx < col_begin+10:
print 'strech left !'
self.setSpan(row, col-1, 1, 2)
elif clicx > col_end-10:
print 'strech right !'
self.setSpan(row, col, 1, 2)
#
class MainWindows(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setGeometry(300, 150, 1140, 630)
self.GridLayout = QtGui.QGridLayout()
self.setLayout(self.GridLayout)
self.GridLayout.addWidget(QtGui.QLabel("some stuff...", self), 0, 0)
self.table = PlanningTable(self)
self.nbrow, self.nbcol = 10, 10
self.table.setRowCount(self.nbrow)
self.table.setColumnCount(self.nbcol)
self.GridLayout.addWidget(self.table, 1, 0, 20, 20)
self.show()
#
#
def main():
global MainWin
app = QtGui.QApplication(sys.argv)
MainWin = MainWindows()
sys.exit(app.exec_())
#
if __name__ == '__main__':
main() |
Partager