Getting the screen coordinate of the top left corner of a QWidget
I'm making a virtual environment with Qt's OpenGL widget and I want to be able to "trap" the mouse in the center of the widget. My idea was to do this:
Code:
QPointF widgetPos
= mapToGlobal
(pos
());
QCursor::setPos(widgetPos.
x() + width
()/2, widgetPos.
y() + height
()/2);
However, widgetPos doesn't contain the top left corner of the screen as I would have hoped, so the cursor gets locked at the wrong position. Am I going about this the wrong way?
Re: Getting the screen coordinate of the top left corner of a QWidget
You could get the top left corner with
Code:
this->rect().topLeft()