3

I can draw a solid-color line easily in Qt, but now I need to draw a line by inverting the original pixels, or perhaps XOR-ing the QBrush.

I'm asking for the equivalent of SetROP2(R2_NOT) or SetROP2(R2_XORPEN) in Win32.

Is that possible using Qt? I want to do it so I can easily "unpaint" it later.

sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

10

You can do it like this:

QPainter dc(widget);

dc.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
dc.setPen(QColor(0xff, 0xff, 0xff));

dc.drawEllipse(center, r1, r2);

Other composition modes are described in the QPainter documentation. To undo individual graphics operations, this one should be exactly what you want, though -- just set the same pen you used in the first place and redraw the shape.

Wintermute
  • 42,983
  • 5
  • 77
  • 80