Results 1 to 3 of 3

Thread: transfer screen x,y coordinate to another machine

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default transfer screen x,y coordinate to another machine

    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: transfer screen x,y coordinate to another machine

    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
    Qt Code:
    1. QMouseEvent * event;
    2.  
    3. QPoint point = event->globalPos();
    4. QSize size = qApp->desktop()->screen()->size();
    5. point.setX(100 * point.x() / size.width());
    6. point.setY(100 * point.y() / size.height());
    7.  
    8. // send point
    To copy to clipboard, switch view to plain text mode 

    On destination machine
    Qt Code:
    1. QPoint point;
    2. // receive point
    3.  
    4. QSize size = qApp->desktop()->screen()->size();
    5. point.setX(size.width() * point.x() / 100);
    6. point.setY(size.height() * point.y() / 100);
    7.  
    8. //use the point
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default Re: transfer screen x,y coordinate to another 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.
    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
    Qt Code:
    1. QMouseEvent * event;
    2. QPoint point = event->globalPos();
    3. QSize size = qApp->desktop()->screen()->size();
    4. point.setX(100 * point.x() / size.width());
    5. point.setY(100 * point.y() / size.height());
    6.  
    7. // send point
    To copy to clipboard, switch view to plain text mode 
    Last edited by saman_artorious; 11th August 2013 at 13:05.

Similar Threads

  1. knowing screen coordinate
    By riarioriu3 in forum Qt Programming
    Replies: 3
    Last Post: 10th July 2012, 09:38
  2. Replies: 1
    Last Post: 18th May 2011, 15:36
  3. Replies: 7
    Last Post: 19th April 2011, 13:20
  4. Replies: 2
    Last Post: 11th June 2010, 08:23
  5. Replies: 2
    Last Post: 22nd December 2009, 21:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.