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. How to achieve this effect with QPixmap?
Forum Updated to NodeBB v4.3 + New Features

How to achieve this effect with QPixmap?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpainterqpixmapqimagepixmappaint
7 Posts 3 Posters 2.2k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    John27
    wrote on 23 May 2018, 14:52 last edited by John27
    #1

    Assume you have following QPixmap pixmap1 (also assume everything is a background except the black rectangle):

    pixmap1

    and pixmap2 (that has the same background as pixmap1 with the same black rectangle which is just moved a bit):

    pixmap2

    and I want to kind of merge them, so they'll look like following pixmap3:

    pixmap3

    Is there any way to achieve that effect in Qt?

    I thought I can use QPainter, but I don't know how to set the background's opacity to 0.

    Also, would it be possible to consider background as everything except the rectangle and the black circle, so the circle could also move and be merged like the rectangles simultaneously?

    E.g.:

    changed pixmap2 (as you can see, the circle also moved):

    changed pixmap2

    and changed pixmap3 (pixmap1 merged with changed pixmap2):

    changed pixmap3

    I apologise if something is unclear, let me know then.

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 May 2018, 15:08 last edited by
      #2

      Hi and welcome to the forums
      Do you know location of the black rect?
      You could use clipping to not draw anything on top of pix1 that is not within
      area.
      If that is not an option it depends on what background is.
      If solid colors with no anti aliasing then something like
      http://doc.qt.io/qt-5/qimage.html#createMaskFromColor
      or QImage QImage::createHeuristicMask(bool clipTight = true)
      Might be able to mask out the "background" in a good way.

      I assume you try to visualize some movement of an object over a background you want to stay the same as in pix1 ?

      J 1 Reply Last reply 23 May 2018, 18:29
      1
      • M mrjj
        23 May 2018, 15:08

        Hi and welcome to the forums
        Do you know location of the black rect?
        You could use clipping to not draw anything on top of pix1 that is not within
        area.
        If that is not an option it depends on what background is.
        If solid colors with no anti aliasing then something like
        http://doc.qt.io/qt-5/qimage.html#createMaskFromColor
        or QImage QImage::createHeuristicMask(bool clipTight = true)
        Might be able to mask out the "background" in a good way.

        I assume you try to visualize some movement of an object over a background you want to stay the same as in pix1 ?

        J Offline
        J Offline
        John27
        wrote on 23 May 2018, 18:29 last edited by John27
        #3

        @mrjj Hi, thanks for your fast reply and sorry for my late reply.

        The object moves almost all the time and I want to keep track of its movements. (it's not 100% true, because I need for some other reasons, but I think you get the idea).
        I've already thought about the mask, but what if the object would have a texture loaded from a file and it wouldn't be solid?
        The idea with clipping would be good, though what if the are couple of objects? It wouldn't be too efficient, IMO.

        I think either I've explained something wrong or there's no good solution for me. The first option is more likely.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 23 May 2018, 19:41 last edited by
          #4

          Do you need to do it with QPixmap or are you just trying stuff? this should be something very easy to do with QtQuick Scenegraph/QGraphicsView

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          J 1 Reply Last reply 24 May 2018, 05:20
          0
          • V VRonin
            23 May 2018, 19:41

            Do you need to do it with QPixmap or are you just trying stuff? this should be something very easy to do with QtQuick Scenegraph/QGraphicsView

            J Offline
            J Offline
            John27
            wrote on 24 May 2018, 05:20 last edited by
            #5

            @VRonin I grab this pixmap from QGraphicsView, so could you post your solution, please?

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 24 May 2018, 06:56 last edited by
              #6

              Are the items all different graphic items?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              J 1 Reply Last reply 24 May 2018, 07:32
              1
              • V VRonin
                24 May 2018, 06:56

                Are the items all different graphic items?

                J Offline
                J Offline
                John27
                wrote on 24 May 2018, 07:32 last edited by John27
                #7

                @VRonin Yes, they are, but the pixmap is just grabbed QGraphicsView's content using grab() method.

                1 Reply Last reply
                0

                1/7

                23 May 2018, 14:52

                • Login

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