[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] Getting cell coordinates in QTable's contextMenuEvent (code
From: kgi <iacovou () gmail ! com>
Date: 2005-12-20 13:42:37
Message-ID: 200512202121.09957.iacovou () gmail ! com
[Download RAW message or body]
Hi there.
I'm adding a context menu to a QTable widget, and am trying to work out which
cell has received the context menu event. I'm using the approach given in the
code snippet below.
I was originally stumped that the coordinates received by contextMenuEvent()
didn't seem to reflect the table being scrolled, but I found a workaround
based upon [1].
Now my problem is that the row/col system seems to be asymmetrical; that is:
(all clicks are 'right' clicks):
- clicking on the vertical header reports 'row = 0'
- clicking on the row labelled '1' reports 'row = 1'
But:
- clicking on the horizontal header reports 'col = 0'
- clicking on the column labelled '1' reports 'col = 0'
- clicking in the last row (labelled '40') reports 'row = -1'
Does anyone have any idea why this is the case and what the 'right' way to
work around it would be?
Thanks,
Ricky
=======================================================
import sys
from qt import *
from qttable import QTable
class MyTable ( QTable ):
def __init__ ( self, *args ):
QTable.__init__ ( self, *args )
def contextMenuEvent ( self, cmev ):
cmev.accept()
x = cmev.x()
y = cmev.y()
xoffset = + self.horizontalHeader().offset()
yoffset = + self.verticalHeader().offset()
col = self.columnAt ( x + xoffset )
row = self.rowAt ( y + yoffset )
print "X: ", x
print "Y: ", y
print "Xoff: ", xoffset
print "Yoff: ", yoffset
print "col: ", col
print "row: ", row
if __name__ == '__main__':
numRows = 40
numCols = 5
app = QApplication ( sys.argv )
table = MyTable ( numRows, numCols )
table.show()
app.setMainWidget ( table )
app.exec_loop()
==========================================================
[1] http://lists.trolltech.com/qt-interest/2002-01/thread00017-0.html
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic