PDA

View Full Version : Draw line with inverted background color



viswanath
20th January 2010, 04:50
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

numbat
20th January 2010, 07:23
Have a look at QPainter::setCompositionMode (http://qt.nokia.com/doc/4.6/qpainter.html#setCompositionMode).

viswanath
20th January 2010, 07:46
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

mrhill
12th November 2011, 02:55
Try this:


QPainter *painter;

painter->setCompositionMode(QPainter::RasterOp_SourceXorDes tination);
painter->setPen(QColor(0xFF,0xFF,0xFF));
painter->drawLine(x1, y1, x2, y2);


Cheers,
mrhill

--
Datahammer 7yuv (http://datahammer.de/) - the hex editor and raw image data viewer built with QT

d_stranz
12th November 2011, 03:57
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.