Results 1 to 8 of 8

Thread: Suggestions for drawing with mouse on GraphicsScene

  1. #1
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Suggestions for drawing with mouse on GraphicsScene

    I'm looking for suggestions on how to solve this problem. Basically what I have is a QGraphicsScene with a number of QGraphicPixmapItems. I want the user to be able to take the mouse and draw line trails (not straight lines), sort of like scribling over the image with a red Pen. I then need to be able to save off the trails they drew to a file so that it can be loaded again at a future point in time.

    Would the best thing to do is create another GraphicsItem subclass that reads the mouse input and the paints the lines? Or should I subclass the Graphics Scene and add functionality in there?

    Just curious what your thoughts are.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    Your scribbling should be either a separate item or a series of line items. They should be created either by the scene or by the view as a result of handling mouse events in one of the two mentioned entities.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    Do you think it would be sufficient to use the dragMoveEvent or a combination of (MousePress, MouseRelease, MouseMove) and then capture the mouse Delta and

    Qt Code:
    1. NewLine = QGraphicsScene::addLine(...);
    2. QList<QGraphicsLineItem*> LineList.push_back(NewLine);
    3.  
    4. // Later on write out the QList to a file
    To copy to clipboard, switch view to plain text mode 

    My only concern is that if they draw lots of curvy lines it will eat up tons of memory.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    Definitely not dragMoveEvent(). The other combination should be fine but I'd suggest to make all your scribble items children of some other item instead of making them directly children of the scene. But both approaches will work, it's just a matter of what you can (and want) do with the drawing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    Ok, I'm working on this now. I'll report back with my progress for future reference for others...

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    I guess you can also refer to the scribble example in Qt Demos

  7. #7
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    Yeah I found that one a while ago and I was looking for it yesterday. Thanks for the name hint.

    It uses a QImage and performs line draws onto the QImage. I'm wondering if it would be better to use either:

    a.) A list of QGraphicsLineItems that are drawn consecutively or,
    b.) A QImage that is the size of the original image I'm drawing on and then do direct pixel modifications.

    I suppose if there are few scribbles the memory requirement for the graphicslineitems would be much less, but if there are LOTs of scribles then QImage might be better?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for drawing with mouse on GraphicsScene

    The fact that the demo works on an image doesn't mean you can't do the same on a widget (or whatever else QPainter can paint on).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Mouse Drawing in opengl
    By sdastagirmca in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2009, 09:32
  2. transfer graphicsscene on form1 to graphicsscene on form2
    By rogerholmes in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2009, 20:37
  3. Line in GraphicsScene
    By konvex in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2008, 12:53
  4. GraphicsScene Question
    By QbelcorT in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2008, 08:03
  5. GraphicsScene Background repainting
    By manojmka in forum Qt Programming
    Replies: 3
    Last Post: 18th December 2007, 10:33

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.