Results 1 to 7 of 7

Thread: resize Rectangle box on imge using mouse events

  1. #1
    Join Date
    Oct 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question resize Rectangle box on imge using mouse events

    hii..to all
    i am new to Qt and for my application need i want draw rectangle on image and drag and drop to another position and resize it properly using handlers.earlier am using qrubberband on Qlabel but am not able to resize it.any one please help me

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: resize Rectangle box on imge using mouse events

    I think you need to use QGraphicsView framework.
    Where you will have view, scene & Item (QGraphicsView, QGraphicsScene, QGraphicsItem).

    1. You create view & set scene to it & draw image on the scene.
    2. Now you customized QGraphicsItem (implement a new class which inherits QGraphicsItem) which should draw rectangle (you can implement this in paint even of this class & Item should be QGraphicsItem::ItemIsMovable, check more flags in Qt doc).
    3. Now in Scene (you need to inherit QGraphicsScene also) you re implement mousePress, mouse move & mouse release events. with mouse press & mouse move events you will get mouse coordinates so that you can draw your rectangle during mouse press & move.


    you can check http://doc.qt.io/qt-4.8/qt-demos-chip-example.html example for graphics view frame work.
    Last edited by prasad_N; 16th November 2015 at 12:32. Reason: spelling corrections
    Thanks :-)

  3. #3
    Join Date
    Oct 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: resize Rectangle box on imge using mouse events

    Thank u very much for replyy.


    I have a mainwindow inherited from QMainWindow, This contains a central widget which holds a scene and a view.In scene i have image now i want to draw a rectangle on image and rectangle should be moveble ,resizeble. i am having same problem with mouse events .now i am getting mouse events fine in QGraphicsscene using QEvents .but i want to add a push button in form for mouse events to draw rectangle and it is moveble .so how can i proceed ..? please help me it is most important to me in my application

    vk41286

  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: resize Rectangle box on imge using mouse events

    Quote Originally Posted by ranjithreddykommareddy View Post
    but i want to add a push button in form
    Adding a button is easy, just add both the current widget and the button into a container widget and use that as the central widget.
    And it is nicely not related to manual mouse event handling at all, that will continue to work as part of your existing widget.

    Cheers,
    _

  5. #5
    Join Date
    Oct 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: resize Rectangle box on imge using mouse events

    thanks for reply but how to resize rectangle with mouse events

  6. #6
    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: resize Rectangle box on imge using mouse events

    Oh, a double poster.
    Don't we love how they waste everone's time?

    http://www.qtcentre.org/threads/6460...658#post285658

    Cheers,
    _

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: resize Rectangle box on imge using mouse events

    But yet the FileWalker thread stands at 4 pages and 62 posts and shows no sign of ending before global warming drowns us all... I was very tempted to simply write the stupid program and post it, but then I realized it would be like shouting at a deaf person.

Similar Threads

  1. Replies: 5
    Last Post: 12th March 2013, 15:58
  2. Move a image over another imge
    By chong_kimkeang in forum Newbie
    Replies: 11
    Last Post: 5th October 2012, 11:29
  3. Replies: 3
    Last Post: 8th October 2011, 10:46
  4. Replies: 2
    Last Post: 9th May 2011, 03:04
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13

Tags for this Thread

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.