Results 1 to 4 of 4

Thread: Flip part of drawing in a QPaintDevice

  1. #1
    Join Date
    Sep 2015
    Posts
    7
    Thanks
    2

    Default Flip part of drawing in a QPaintDevice

    Hi All,

    I'd like to paint part of a drawing flipped horizontally on a QPaintDevice.

    Here is the problem:

    I have a QWidget on which I want to draw a checkbox flipped horizontally at some position inside the widget.
    The porblem is that the checkbox is smaller than the size of the QWidget, so painter.translate(-1.0,0) won't work because the checkbox will appear at the opposite side of the widget.

    The solution I found actually is to draw the checkbox flipped inside a pixmap of the size of the checkbox (in that case transtale() will do the job) and then draw the pixmap on the widget.

    Is there a faster way to this (flip only part the painting inside the widget) without intermediate structures ?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Flip part of drawing in a QPaintDevice

    translate moves the origin on the drawing, flipping would be scaling with -1 on the axis you want to flip.
    Potentially translated to the origin of the flip first, of course.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    7
    Thanks
    2

    Default Re: Flip part of drawing in a QPaintDevice

    Ok in fact scale(-1,0) has nothing to do with the paint device width. It just multiplies X coordinates passed to qpainter by -1.

    so to re-align my checkbox inside the original rect, I must do:

    bounds.getRect(&x,&y,&w,&h); // this is where I must draw
    painter->scale(-1.0,1.0); // x becomes -x
    painter->translate(-2*x-w,0); // then bring it back to original position. transformations are cumulative

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Flip part of drawing in a QPaintDevice

    Quote Originally Posted by dextermagnific View Post
    Ok in fact scale(-1,0) has nothing to do with the paint device width. It just multiplies X coordinates passed to qpainter by -1.
    Of course, why would that change the width of the device?
    The transformations are applied to drawing operations, not to devices properties.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    dextermagnific (25th September 2015)

Similar Threads

  1. Qwt minimize drawing part
    By lamle in forum Qwt
    Replies: 3
    Last Post: 13th April 2012, 13:40
  2. PyQt4 - part of a QPixmap not drawing correctly
    By emorris in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2012, 15:17
  3. Replies: 4
    Last Post: 27th December 2011, 11:34
  4. Page flip effect
    By emrares in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2010, 13:01
  5. How to flip QImage
    By lni in forum Qt Programming
    Replies: 4
    Last Post: 9th March 2009, 17:28

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.