
Originally Posted by
mickey
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 ) ) );
QCursor::setPos( mapToGlobal( QPoint( width()/2, height()/2 ) ) );
To copy to clipboard, switch view to plain text mode
Bookmarks