1
votes

This is an oscilloscope. I want a round, green window with a reticle over it.

If I were doing this directly, I'd fill a rect with black, draw a 0-alpha ellipse in it, and simply composite that over the other pixmap where the pixels where set to green after I had the scope trace drawn on the green pixmap.

It doesn't appear to work that way. I can fill the pixmap with transparency:

m_grdPixmap.fill(Qt::transparent);

and sure enough, I get a fully transparent pixmap. I can't seem to draw anything on it, even when I construct a pen with rgba. It stubbornly stays transparent.

If I do it the other way round, that is, fill it with black:

m_grdPixmap.fill(QColor::fromRgb(0, 0, 0));

Then try to draw an ellipse on it using (what I hope is a) transparent pen, it stubbornly stays opaque:

painter.setPen(qRgba(0,0,0,0));

...or...

painter.setPen(qRgba(0,0,0,255));

I'm sure I'm missing something. This should be simple, right?

1

1 Answers

0
votes

Oh, good grief. It's not just wrong, it's broken.

Here's what you have to do:

  1. clear the pixmap to fully transparent, a magical step with no meaning to the final image's pixel content, except if you don't do it, nothing works:

    m_grdPixmap.fill(QColor::fromRgb(0,0,0,0));

  2. then fill it with the actual color you want to form the "window surround", non-transparent:

    qb = QBrush(QColor::fromRgb(0,0,0,255));
    painter.setBrush(qb);
    painter.drawRect(0,0,w,h);

  3. then punch out the transparent ellipse (green here, but doesn't matter):

    qb = QBrush(QColor::fromRgb(0,255,0,0));
    painter.setOpacity(1.0);
    painter.setBrush(qb);
    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.drawEllipse(center,(int)aw,(int)aw);

  4. Then composite this over the actual scene you want the "window" to reveal:

    painter.begin(&m_scopePixmap);
    painter.drawPixmap(0,0,m_grdPixmap);

...this is obscure, opaque, and near as I was able to tell, undocumented.

But there it is. And it works.