Draw line with inverted background color
Hi All
How can I draw a line with inverted background color using Qt. To be more clear I would like to draw a line based on mouse move and draw another line with next mouse move removing the old mouse move drawn line. I do not want to loop all the points to draw. I will looking for the option MFC SetROP2 (R2_NOT) type option with Qt. Is it possible with Qt. Currently I'm using Qt4.4.1 in Linux. Pls let me know if I missed anything or posted in a wrong form.
Thanks and Regards
J.Viswanath
Re: Draw line with inverted background color
Re: Draw line with inverted background color
Thanks numbat for the quick reply. I tried QPainter::setCompositionMode with most of the options but it dint worked well. Can you suggest me how should I try with QPainter::setCompositionMode as it dint worked to draw new line with inverted background color.
Thanks and Regards
J.Viswanath
Re: Draw line with inverted background color
Try this:
QPainter *painter;
painter->setCompositionMode(QPainter::RasterOp_SourceXorDe stination);
painter->setPen(QColor(0xFF,0xFF,0xFF));
painter->drawLine(x1, y1, x2, y2);
Cheers,
mrhill
--
Datahammer 7yuv - the hex editor and raw image data viewer built with QT
Re: Draw line with inverted background color
By far the easiest way to do this is not to do tricks with pen modes. Simply create a widget with a transparent background on top of the widget you want to draw the rubber band on, and draw it with whatever pen want in ordinary drawing mode. Each time the mouse moves, call update(), the window will be erased, and then you draw the new line. When you want to stop using the rubber band, just "hide" the rubber band window.