Results 1 to 5 of 5

Thread: Draw line with inverted background color

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Draw line with inverted background color


  3. #3
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  4. #4
    Join Date
    Nov 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb 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

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Draw a line
    By Daan in forum KDE Forum
    Replies: 1
    Last Post: 27th August 2009, 17:29
  2. Draw Line
    By aloysiusjegan in forum Qwt
    Replies: 4
    Last Post: 12th February 2009, 11:02
  3. Draw Line :confused:
    By sabeesh in forum Qt Programming
    Replies: 9
    Last Post: 24th January 2008, 11:26
  4. Best way to draw a Line
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 09:57
  5. Slot to color background of line edit on textedited
    By tpf80 in forum Qt Programming
    Replies: 5
    Last Post: 21st June 2007, 09:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.