Results 1 to 3 of 3

Thread: Interesting QPainter Question... Not sure if its possible

  1. #1
    Join Date
    Sep 2009

    Default Interesting QPainter Question... Not sure if its possible

    Im sure your all familiar with the "Scribble" Qt demo included when you install the Qt SDK. My question is based off that demo.

    Basically, drawing a pen over an image or QWidget is easy, set the pen to draw and track mouse events, not too hard. But what if i want to erase some of the drawings i made, but not all of them.

    imagine i draw a giant line horizontally threw my image, and i want to erase small segments of the line, to produce a segmented line, but i dont want to do this simply by erasing rectangles (eraseRect), because the drawings i make on the image arent necessarily a straight line.

    I had a few ideas how to do this:
    1. as im drawing my "erasure" i call a get color on each pixel of the original image and just draw those colors over my new, "edited" image. The only issue with that is it can take up a lot of processor resources if you are checking the color at each pixel.

    2. When i load the image i am trying to draw on, load it twice, and keep one image behind the other. When i draw, i am drawing over the front image, but when i want to erase, all i do is erase the forground image, which would then show the image behind it (unedited) thus making it look like i am erasing my custom pen marks.

    basically, my question is how can i implement the second option, it seems to be the best way to do it, but im not sure how to erase anything with QPainter except for the eraseRect call.

    Any suggestions are greatly appreciated! thanks for the help

    EDIT: Alright, it seems that eraseRect() would work for me, except that it also erases the background image i am drawing... is there anyway i can set the background image (QImage) to be un-editable for a short period of time?
    Last edited by Slewman; 22nd February 2010 at 22:02.

  2. #2
    Join Date
    Jan 2009
    The Netherlands and Spain
    Thanked 18 Times in 18 Posts
    Qt products

    Default Re: Interesting QPainter Question... Not sure if its possible

    You could store every item (line, rectangle etc.) as a QPainterPath allowing you to redraw the image completely, partially or modified. Simply adjust some properties of an object to modify the picture.

  3. #3
    Join Date
    Sep 2009

    Default Re: Interesting QPainter Question... Not sure if its possible

    yea i tried that, it didnt exactly give me the behavior i was looking for.

    i really think the best way to do it would be to draw 2 images on top of each other. the one in the forground would be the one i could draw onto, and the one in the background would just be there to fill in the spots that i erase from the forground picture. does this make sense? how can i go about drawing 2 images like this?

Similar Threads

  1. QPainter - drawRoundedRect Question
    By ChrisReath in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 15:14
  2. QPainter Question
    By atb in forum Qt Programming
    Replies: 3
    Last Post: 18th March 2008, 12:28
  3. QPainter bounds question
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2007, 15:09
  4. Question on QPainter setWindow use
    By impeteperry in forum Qt Programming
    Replies: 14
    Last Post: 8th August 2006, 14:26
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 12:24


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.