PDA

View Full Version : Getting the screen coordinate of the top left corner of a QWidget



blooglet
18th May 2011, 13:54
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:


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?

meazza
18th May 2011, 15:36
You could get the top left corner with

this->rect().topLeft()