PDA

View Full Version : transfer screen x,y coordinate to another machine



saman_artorious
8th August 2013, 10:34
There are two systems, when screen is clicked on the first one, x & y coordinates shall be transfered to the second machine via socket.
The monitor sizes and resolutions may differ. Is there any way to get the exact coordinate on the other machine?

Santosh Reddy
8th August 2013, 11:04
Is there any way to get the exact coordinate on the other machine?
When the monitor sizes and resolutions can differ, you cannot rely on the exact coordinate, you should convert the coordinates in to relative (say % of width, % of height) cooridinates and then sedn them across to other machine.

On source machine


QMouseEvent * event;

QPoint point = event->globalPos();
QSize size = qApp->desktop()->screen()->size();
point.setX(100 * point.x() / size.width());
point.setY(100 * point.y() / size.height());

// send point


On destination machine


QPoint point;
// receive point

QSize size = qApp->desktop()->screen()->size();
point.setX(size.width() * point.x() / 100);
point.setY(size.height() * point.y() / 100);

//use the point

saman_artorious
11th August 2013, 06:58
When the monitor sizes and resolutions can differ, you cannot rely on the exact coordinate
, you should convert the coordinates in to relative (say % of width, % of height) cooridinates and then sedn them across to other machine.
my is different, I have a QGLWidget inside main window. I need to transfer the coordinates of x & y within this gl widget.
whatever the resolution and screen might be, is the QGLWidget have the same size, we will always get the same coordinates in both using event.x and event.y wouldn't we?

On source machine


QMouseEvent * event;
QPoint point = event->globalPos();
QSize size = qApp->desktop()->screen()->size();
point.setX(100 * point.x() / size.width());
point.setY(100 * point.y() / size.height());

// send point