Results 1 to 4 of 4

Thread: how to use setDragMode in QGraphicsView to draw a circle when user drags over figure

  1. #1
    Join Date
    Aug 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default how to use setDragMode in QGraphicsView to draw a circle when user drags over figure

    I know how to use the setDragMode in QGraphicsView to allow the user draw a rectangle on figure. I want an easy way to be able to do the same thing only this time around, when the user clicks and drags on the figure, a circle should be drawn, and not a rectangle. I dont know if that is possible, but i would really appreciate your suggestions.

    Here is a section of my code:
    Qt Code:
    1. void Scene::setMode(Mode mode){
    2. sceneMode = mode;
    3. QGraphicsView::DragMode vMode =
    4. QGraphicsView::NoDrag;
    5. if(mode == DrawCircle){
    6. makeItemsControllable(false);
    7. vMode = QGraphicsView::RubberBandDrag;
    8. }
    9. else if(mode == DrawRect){
    10. makeItemsControllable(true);
    11. vMode = QGraphicsView::RubberBandDrag;
    12. }
    13. QGraphicsView* mView = views().at(0);
    14. if(mView)
    15. mView->setDragMode(vMode);
    16. }
    17.  
    18. void Scene::makeItemsControllable(bool areControllable){
    19. foreach(QGraphicsItem* item, items()){
    20. item->setFlag(QGraphicsItem::ItemIsSelectable,
    21. areControllable);
    22. item->setFlag(QGraphicsItem::ItemIsMovable,
    23. areControllable);
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    When mode == DrawCircle, i want the user to be able to drag and draw a circle on the figure instead of a rectangle. Thanks in advance.
    Last edited by anda_skoa; 12th August 2016 at 15:22. Reason: fix code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to use setDragMode in QGraphicsView to draw a circle when user drags over fig

    I don't think the rubber band drawing can easily be customized, but could likely implement your own rubber band circle by deriving from the view class, implementing the mouse even handler methods an drawing the circle in drawForeground().

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to use setDragMode in QGraphicsView to draw a circle when user drags over fig

    Thanks for the advice.


    Added after 10 minutes:


    Can you give me more information on what you described, or probably help me with a link to where a similar situation is handled? because am pretty new to qt and c++
    Last edited by thierry Joel; 12th August 2016 at 18:36.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to use setDragMode in QGraphicsView to draw a circle when user drags over fig

    Maybe the ScribbleExample http://doc.qt.io/qt-5/qtwidgets-widg...e-example.html as a starting point on how to do event handling in derived classes and how painting works.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    thierry Joel (13th August 2016)

Similar Threads

  1. how to draw a circle using qml
    By hema in forum Qt Quick
    Replies: 2
    Last Post: 8th August 2016, 12:48
  2. Replies: 7
    Last Post: 24th May 2011, 04:36
  3. Replies: 2
    Last Post: 16th May 2011, 08:06
  4. draw a circle
    By NewLegend in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2010, 16:01
  5. Draw figure underneath other figure
    By Mnemonic in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 13:38

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.