Results 1 to 12 of 12

Thread: QPainter, scale(), and setFont()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QPainter, scale(), and setFont()

    Try this:
    Qt Code:
    1. void paintEvent( QPaintEvent * )
    2. {
    3. QPainter p( this );
    4.  
    5. p.save();
    6.  
    7. // set up "traditional" coordinate system
    8. p.setWindow( -10, -10, 20, 20 );
    9. p.scale( 1.0, -1.0 );
    10. QTransform t = p.combinedTransform();
    11.  
    12. // draw the graph
    13. p.drawLine( 0, 0, 5, 5 );
    14.  
    15. // revert to the default coordinate system
    16. p.restore();
    17.  
    18. // draw labels in the Right Place(tm) using t transform
    19. QPoint pt( 7, 7 );
    20. p.drawText( t.map( pt ), "xxx" );
    21. }
    To copy to clipboard, switch view to plain text mode 
    Instead of using save()/restore() you can prepare the right QTransform yourself and map all points.

    Another solution is to scale the font, but it might not work with all fonts. Also take a look at Qwt.

  2. The following user says thank you to jacek for this useful post:

    c_07 (16th December 2007)

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.