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 QBitmap, How to achieve this?
QtWS25 Last Chance

QPixmap QBitmap, How to achieve this?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.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.
  • T Offline
    T Offline
    tclin1998
    wrote on last edited by
    #1

    Hi:

    @
    QPixmap workPix;
    QBitmap maskBmap;
    @

    workPix's background is 'black', and then fill with 'green' and solid patten using QPainter.

    maskBmap's some area is '1' and some is '0'.

    For Qt 3.3, I can use
    workPix.setMask(makBmap) so the result of workPix is that overlapped with maskBmap's '1' area is green,
    '0' 's area is black.

    For Qt 4.6. The above scheme does not work any more.
    How can I achieve the same results in Qt 4.6?

    Thanks!

    -Todd

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Can you rephrase the whole thing? And possibly add some snippets and screenshots?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tclin1998
        wrote on last edited by
        #3

        Thanks for looking into this.
        The following code works fine for 3.3. It does not work for 4.6.
        I look into Qt 3.3 and Qt 4.6 's QPixamp setMask(). They are quite
        different. Not sure how to make the following code work for Qt 4.6.

        -Todd
        @
        ///--- BEGIN

        QPixmap workPix(_guCanvas->getBuffer()->size());

        for (int i = 0; i < _numLayerBmaps; i++) {
        workPix.fill(_guCanvas,0,0); // fill workPix with the background of guCanvas, which is balck

        QPainter p;
        if (_shapeViaVisibleAry[i]) {    //  <----- a QBitmap
          if (_shapeViaBmapsFill[i].isNull()) {
            continue;
          }
        

        // Use QPainter to fill workPix with color patterns
        p.begin(&workPix);
        if (i % 2) { // fill with pattern in foregorund
        p.fillRect(workPix.rect(), QBrush(ppColor[i], ppBrushPattern[PAT_VIA_CUT]));
        } else {
        p.fillRect(workPix.rect(), QBrush(ppColor[i], ppBrushPattern[PAT_SHAPE]));
        }
        p.end();

        //
        // I want to do AND operation on workPix using shapeViaBmapsFill[i]
        // if the bit on shapeViaBmapsFill[i] is '1', I want workPix to store workPix's
        // original foreground, if it's '0', workPix to store background.
        //
        workPix.setMask(_shapeViaBmapsFill[i]);

        }
        

        }

        //---- END ---
        @

        Edit: please use the @ tags to format your code and deleted double post of code section; Andre

        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