Window position with respect to screen and width and height of window
-
Hi
Using Qt 4.8
I am trying to bind mouse cursor to the center of my application.If application is in fullscreen it works with following code
@
int middleX = QApplication::desktop()->width() >> 1;
int middleY = QApplication::desktop()->height() >> 1;QPoint newMousePos; newMousePos.setX(middleX); newMousePos.setY(middleY); QCursor::setPos(newMousePos);
@
and it works.
But how do I do this when application is not fullscreen mode?
Thanks in advance
-
Every QWidget has methods to map between the relevant coordinate systems. Did you look into these?
-
Thanks for the reply Andre.
I tried various codes on the web, having frameGeometry() and many things
But nothing seems to workI would appreciate if you can demonstrate some code
-
Do it in steps:
get the center point of the geometry of your window.
then, map that coordinate to the right coordinate system (look for functions in QWidget that start with mapTo and mapFrom)
set the mouse using those coordinates.
-
Well, I think I understand these steps. I have already done this for fullscreen mode.
I do not know "exactly how" to get the geometry of the window? Once I have that things will be easy..