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. QPixmap and QPainter (Qt 5)
Forum Updated to NodeBB v4.3 + New Features

QPixmap and QPainter (Qt 5)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.3k 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.
  • A Offline
    A Offline
    ARMORIUM
    wrote on last edited by
    #1

    So i am painting some QPixmaps in widget's PaintEvent using QPainter, and i want to change one color on all of them to trasparent. What is the best way to do it? I am porting my program from Qt 4, and there were method setAlphaChannel, but now i really don't know how to solve this problem. Tryed something like this

    @
    landscape[0].load("gfx/landscape/mount.bmp");
    landscape[0].setMask(landscape[0].createMaskFromColor(QColor(100,100,100),Qt::MaskOutColor));
    @

    But it doesn't work.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      This sounds like a job for QImage, not for QPixmap...

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ARMORIUM
        wrote on last edited by
        #3

        It is posible to replace qpixmap with qimage, but what is the best way replace selected colour to transparent in my image?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          How about creating a mask using QImage::createMaskFromColor, and then using QPixmap::setMask?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ARMORIUM
            wrote on last edited by
            #5

            So solution was pretty easy using qimage i wrote:

            @
            landscape[0].load("gfx/landscape/mount.bmp");
            landscape[0].setAlphaChannel(landscape[1].createMaskFromColor(qRgb(100,100,100),Qt::MaskOutColor));
            @

            So this code makes currient rgb color for image transparent. Thank's.

            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