Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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
  •  
Qt is a trademark of The Qt Company.