Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Responsibility of cropping QPixmap in paintEvent

Responsibility of cropping QPixmap in paintEvent

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SeeLookS Offline
            SeeLookS Offline
            SeeLook
            wrote on last edited by SeeLook
            #5

            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                |            |
            ------------------------------------------            |
                                 |................................|
            */
            
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SeeLookS Offline
                SeeLookS Offline
                SeeLook
                wrote on last edited by SeeLook
                #7

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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • SeeLookS Offline
                    SeeLookS Offline
                    SeeLook
                    wrote on last edited by
                    #9

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

                    Thanks for clue!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved