Results 1 to 2 of 2

Thread: Getting the screen coordinate of the top left corner of a QWidget

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. QPointF widgetPos = mapToGlobal(pos());
    2. QCursor::setPos(widgetPos.x() + width()/2, widgetPos.y() + height()/2);
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting the screen coordinate of the top left corner of a QWidget

    You could get the top left corner with
    Qt Code:
    1. this->rect().topLeft()
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to meazza for this useful post:

    blooglet (18th May 2011)

Similar Threads

  1. Replies: 4
    Last Post: 13th February 2011, 20:24
  2. Replies: 4
    Last Post: 30th May 2010, 12:55
  3. QTableWidget - Using top left corner cell
    By SteveH in forum Newbie
    Replies: 6
    Last Post: 12th March 2010, 19:33
  4. Replies: 1
    Last Post: 7th September 2008, 10:47
  5. Replies: 7
    Last Post: 15th November 2007, 17:19

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.