Results 1 to 7 of 7

Thread: Problem with window-viewport coordinate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with window-viewport coordinate

    Hi. I have a problem with window-viewport coordinates. In my code I draw a polygon:

    Qt Code:
    1. static const int upPoints_p[4][2] = {
    2. { 49, -49 }, { -49, -49 },
    3. { -10, -10 }, { 10, -10 }
    4. };
    5.  
    6. QPolygon up_p(4, &upPoints_p[0][0]);
    7. painter.setWindow( -50, -50, 100, 100);
    8. painter.drawPolygon(up_p);
    To copy to clipboard, switch view to plain text mode 


    and next, I would like to check mousePressEvent:

    Qt Code:
    1. QPoint point = event->pos();
    2. if( up_p.containsPoint(point, Qt::OddEvenFill) )
    3. {
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    but I have different coordinate. Can someone help me fix my code?

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with window-viewport coordinate

    The event->pos() gives you co-ordinates in the widget world co-ordinates. You perhaps want co-ordinates of mouse click in way you have set the window.
    After having done setWindow() call painter.transform().inverted().map(event->pos()) in paint function. This will give you the co-ordinates in your world.

  3. #3
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with window-viewport coordinate

    Thanks for answer. So, I change my code:

    Qt Code:
    1. void Diagram::mousePressEvent(QMouseEvent *event)
    2. {
    3. QPoint point = event->pos();
    4.  
    5. QPainter painter(&pixmap);
    6. painter.setWindow(-50, -50, 100, 100);
    7.  
    8. QPoint out = painter.transform().inverted().map(event->pos());
    9.  
    10. qDebug() << point.x() << point.y();
    11. qDebug() << out.x() << out.y();
    12. }
    To copy to clipboard, switch view to plain text mode 

    but I still get the same value, for example:

    Qt Code:
    1. 188 158
    2. 188 158
    To copy to clipboard, switch view to plain text mode 

    and I can't check this condition

    Qt Code:
    1. up_p.containsPoint(out, Qt::OddEvenFill)
    To copy to clipboard, switch view to plain text mode 

    because I have polygons defiened like:

    Qt Code:
    1. static const int upPoints_p[4][2] = {
    2. { 49, -49 }, { -49, -49 },
    3. { -10, -10 }, { 10, -10 }
    4. };
    To copy to clipboard, switch view to plain text mode 

    So, what am I doing wrong?

Similar Threads

  1. QGraphicsView Framework coordinate mapping problem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2009, 12:30
  2. Replies: 1
    Last Post: 27th August 2009, 23:06
  3. coordinate problem
    By sai in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 10:21
  4. Replies: 2
    Last Post: 26th February 2009, 10:12
  5. Brushes and window/viewport transformations
    By blukske in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 13:59

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
  •  
Qt is a trademark of The Qt Company.