Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to achieve this effect with QPixmap?

    General and Desktop
    qpainter qpixmap qimage pixmap paint
    3
    7
    1575
    Loading More Posts
    • 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
      John27 last edited by John27

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • J
          John27 @mrjj last edited by John27

          @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 Reply Quote 0
          • VRonin
            VRonin last edited by

            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 Reply Quote 0
            • J
              John27 @VRonin last edited by

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

              1 Reply Last reply Reply Quote 0
              • VRonin
                VRonin last edited by

                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 Reply Quote 1
                • J
                  John27 @VRonin last edited by John27

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post