Results 1 to 4 of 4

Thread: Scribble to GraphicsView

  1. #1
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Scribble to GraphicsView

    Hello,

    I was wondering if it is possible, in Qt, to convert a scribbled paint into a QGraphicsItem.

    What I am trying to do is a scribble area where, for example, I draw a circle with the mouse, and then after the circle is finish and I release the mouse button, then that figure is
    somehow converted into an item I can drag, rotate, and treat as an individual item. The same way, I want to be able to draw a square, and then use that square as a GraphicsView item, get the bounding rect, move it, use collision detection, etc.

    Do you think it is possible to do that in Qt?
    Do you have any suggestions?

    Thank you very much!
    Last edited by rdelgado; 10th November 2009 at 20:19.

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scribble to GraphicsView

    Since you can override any mouse event of your QGraphicsView, and if your mind is clear, of course you can do what you want.
    May be it is not so easy and you might need some well defined design.

    For instance, you can design a drawing tool object, one instance for the circle scribble and another for rect one. A tool object, when activated in an exlusive way, will receive mouse events.

    So you can manage a temporary item with the activated tool that will set a QGraphicsItem according to mouse position and click. So, on right click for example, get the temporary geometry.
    Then you can create your items and set their flags for your needs.

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scribble to GraphicsView

    Hi!

    To get started, you could look into the Qt-boxes demo. The relevant classes are implemented in qtbox.h/cpp.

    There you can see rectangles and circles been created, moved around and resized with the mouse.

    You will probably want to create your items in QGraphicsScene::mousePressEvent, and not when you select the tool.

    Or did I miss the point and you want to really scrible with always the same tool/pen, and you want your application to detect afterwards if its a rectangle or a circle and convert it into the appropriate item?

    For that you will need to keep track of the pens path. Find its geometric center, width and height. Implement an errorfunction, that will give you a score of how good the path matches to a rectangular or an ellipse/circle with those parameters. Maybe go through all the points of your path and add up the absolute distance to the nearest point of the testshape. The one with the lowest score wins then.. I don't think there is a prebuild funtion if thats what you were asking.

    Let me know if you need further help.

    HIH

    Johannes
    Last edited by JohannesMunk; 11th November 2009 at 14:52.

  4. #4
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Scribble to GraphicsView

    Hi,

    Thanks for your help!

    Or did I miss the point and you want to really scrible with always the same tool/pen, and you want your application to detect afterwards if its a rectangle or a circle and convert it into the appropriate item?
    Yes, I want to scribble with the same tool and my application to detect it. I could make my application detect the object and convert it to a shape-item, but what I really want to do is to keep using the scribbled figure as an item.

    I want to make an application similar to Crayon Physics or Numpty Physics and other physics based games, and that is why I wish to know if such functionality is possible on Qt.

    I'll keep studying Qt and working around to see if I can make it.

    Thank you very much!

Similar Threads

  1. The problem when add QAxWidget into graphicsView.
    By Scott Liu in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2009, 06:39
  2. Replies: 2
    Last Post: 5th September 2009, 11:23
  3. GraphicsView paintEvent() method implementation problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 2
    Last Post: 17th August 2009, 06:54
  4. Newbie: Circuits and GraphicsView
    By RY in forum Newbie
    Replies: 10
    Last Post: 1st October 2008, 05:12
  5. QT GraphicsView Help
    By mistertoony in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2007, 04:17

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.