PDA

View Full Version : Change cursor inside QTableview



big4mil
12th November 2010, 18:29
Hi All,

I would like to change the mouse cursor when I move the mouse pointer inside my QTableView over a row.

I've tried this:

void QTableView::mouseMoveEvent( QMouseEvent *pEvent )
{
int iRow = this->rowAt( pEvent->y() );
if( iRow == -1 )
{
this->setCursor( QCursor( Qt::ArrowCursor ));
}
else
{
this->setCursor( QCursor( Qt::PointingHandCursor ));
}
}

But this unfortunately this does not work. The mouse cursor is not changing. What do I wrong? Any ideas?

Many thanks and best regards

high_flyer
15th November 2010, 09:50
Just a guess:
maybe rowAt() uses local Widget coordinates, but the event is giving global.
Try to map to widget coordinates and see if it helps.

big4mil
15th November 2010, 10:35
Hi high_flyer,

with pEvent->y() I'm mapping to the local widget coordinates (pEvent->globalY() is the one which mapps global). Also when I move over a row inside my QTableView I can see (with qDebug()-output) that this function call works fine. But the cursor is not changing.

Any ohter ideas or suggestions?

Best regards

high_flyer
15th November 2010, 10:56
Hmm...
Try first with out specifying a row.
See if at all you get the cursor to change over the widget.

FelixB
15th November 2010, 11:04
a mouseMoveEvent is only generated, if you press a button. If you want to generate the event always, you have to enable mouse tracking for the widget