QPixmap QBitmap, How to achieve this?



  • 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



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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.