[Qt-interest] QTableView, wrong cell index by position
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Wed Jan 21 07:26:05 CET 2009
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Josinei Silva
> Sent: 2009-01-20 21:47
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] QTableView, wrong cell index by position
>
> Hi,
>
> I need to show a tooltip for one column at a QTableView subclass. I.m
> using
> eventFilter to get ToolTip event and show the tooltip when the cursor
is
> over
> the column i need.
>
> But when i'm using these lines to get column index:
>
> QHelpEvent *HelpEvent = static_cast<QHelpEvent *>(Event);
> QModelIndex Index = tbvTable->indexAt( HelpEvent->pos() );
>
> The index position doesn't match with index position of the column
where
> the
> cursor is.
> I got row 0 when the cursor is over the horizontal header and at the
last
> line, i got row -1, column -1.
> I got column 0 when the cursor is over the vertical header and at the
last
> column i got row -1, column -1.
>
> The row is always wrong, at row 0, i got row 1 and so on.
> The column changes at the middle of the column, not at the borders.
>
> It looks like QTableView is not considering Horizontal Header and
Vertical
> Header when calculating the index of a postion.
>
> I should compensate horizontal header and vertical header manualy or
> there's a
> way to tell QTableView to do it?
>
> Thanks
>
> Josinei R. L. Silva
[Scott Aron Bloom]
It sounds like pos() is in the wrong coordinate system.. Its using the
widgets x & y, not the tableview... Could be the viewport etc...
Try getting the global position, then use the
tableviews->mapFromGlobal() to get the tables pos and then determine the
index.
However, IIRC you can also use ToolTipRole in yoru data model and return
QVariant for all the columsn you don't are about, and return the proper
text for the index right there... It's a MUCH cleaner solution
Scott
More information about the Qt-interest-old
mailing list