PDA

View Full Version : cursor



mickey
14th July 2006, 19:30
hi, when I click on qglwiget I need put cursor at middle of widget; this isn't working!
Is this ok? thanks


//paintGL of myWidget class
QCursor::setPos(QPoint(this->x()+this->width()/2, this->y()+this->height()/2 ));

jacek
14th July 2006, 19:41
hi, when I click on qglwiget I need put cursor at middle of widget; this isn't working!
Is this ok?
Unfortunately, not.

Qt docs say:

void QCursor::setPos ( int x, int y ) [static]
Moves the cursor (hot spot) to the global screen position (x, y).
You can call QWidget::mapToGlobal() to translate widget coordinates to global screen coordinates.

But you use coordinates relative to the parent widget:

int QWidget::x () const
Returns the x coordinate of the widget relative to its parent including any window frame. See the "x" property for details.
(it would work if the widget was a top level widget).

This should work:
QCursor::setPos( mapToGlobal( QPoint( width()/2, height()/2 ) ) );