Results 1 to 3 of 3

Thread: Qt4 -> Qt5: QPainter scale

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    2

    Default Qt4 -> Qt5: QPainter scale

    Hello,
    I'm performing some conversion from Qt4 to Qt5. My colleague states, that the code below used to create a rectangle with 1 pixel border, covering nearly whole widget, on Qt 4.8.1

    Qt Code:
    1. QPainter painter( this );
    2. painter.scale( width(), height() );
    3.  
    4. painter.setPen( Qt::green );
    5. painter.setBrush( Qt::yellow );
    6. painter.drawRect( QRectF( 0.1, 0.1, 0.8, 0.8 ) );
    To copy to clipboard, switch view to plain text mode 

    However, when I run this on Qt 5.3.2, the scale works differently. I receive insanely oversized rectangle with really thick border. In other words it is zooming instead of changing distances between points on axes.

    I couldn't find this information in any Qt4->Qt5 migration guide, can someone confirm or deny that anything was changed with scaling method?


    EDIT:

    Looks like this might be the thing:
    Qt Code:
    1. // Qt4:
    2. void QPainter::scale(qreal sx, qreal sy)
    3. {
    4. m.scale(sx, sy);
    5. setMatrix(m, true); // however this calls setWorldMatrix( m ) anyway
    6. }
    7.  
    8. // Qt5:
    9. void QPainter::scale(qreal sx, qreal sy)
    10. {
    11. Q_D(QPainter);
    12. if (!d->engine) {
    13. qWarning("QPainter::scale: Painter not active");
    14. return;
    15. }
    16.  
    17. d->state->worldMatrix.scale(sx,sy);
    18. d->state->WxF = true;
    19. d->updateMatrix();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Is there an easy way to migrate my code?
    Last edited by gavinmagnus; 7th November 2016 at 16:48.

Similar Threads

  1. Replies: 6
    Last Post: 20th March 2014, 10:15
  2. Replies: 2
    Last Post: 26th December 2012, 01:03
  3. QBitmap does not scale correctly with QPainter
    By macaco in forum Qt Programming
    Replies: 0
    Last Post: 8th August 2008, 11:40
  4. QPainter, scale(), and setFont()
    By c_07 in forum Qt Programming
    Replies: 11
    Last Post: 2nd January 2008, 19:46

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.