Responsibility of cropping QPixmap in paintEvent



  • Hi,

    If paintEvent() draws piece of pixmap which is i.e. 1000x1000 entire, but that painted chunk is i.e. just 200x200 in the bottom-right corner of painting area, who is responsible for cropping that pixmap?
    Is this sufficient?:

    QPixmap pixmap(1000, 1000);
    painter.drawPixmap(painter.width() - 200, painter.height() - 200, pixmap);
    

    or drawPixmap(sourceRect, pixmap, destinationRect) has to be used?


  • Lifetime Qt Champion

    Hi,

    If you only want to paint parts of your pixmap, then it's up to you to tell the painter what to paint from the original pixmap.



  • @SGaist Thank You.
    I'm asking in a context:
    when I directly crop a pixmap by defining source and destination rectangles, will it influence on effectiveness?
    Or it is the same like calling drawPixmap with "entire" pixmap, because it will be cropped by Qt routines? I've done that already in many places but I'm wondering is it correct.


  • Lifetime Qt Champion

    Where's you pixmap coming from and how do you determine the part that you want to be painted ?



  • The pixmap is static object - an image loaded from file during app launch time, then scaled according to geometry. Then widgets laying above, paint its part in their paintEvents.

    /*
    ------------------------------------------
    |                                        |
    |                                        |
    |          widget 1                      |
    |                                        |
    |                     -------------------|.............
    |                    |                pix|map         |
    |........................................|            |
    |            widget  |  2                |            |
    ------------------------------------------            |
                         |................................|
    */
    
    

  • Lifetime Qt Champion

    Do you mean that you are painting parts of the pixmap on widget 1 and widget 2 ? How are these two widgets related ?



  • alt text
    The guitar body is that pixmap, when musical score is widget 1 and the fingerboard is widget 2


  • Lifetime Qt Champion

    If I understands things correctly, these two pieces of the pixmap won't really change. If so, it would likely make more sense to store the parts you need to paint and only paint that. That would avoid needles cropping operations.



  • In fact, it is the best solution.
    If there will be already cropped pixmap that simpler call of drawPixmap() remains.

    Thanks for clue!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.