PDA

View Full Version : resize Rectangle box on imge using mouse events



ranjithreddykommareddy
16th November 2015, 10:07
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

prasad_N
16th November 2015, 11:30
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.

ranjithreddykommareddy
7th December 2015, 07:42
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

anda_skoa
7th December 2015, 08:22
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,
_

ranjithreddykommareddy
21st December 2015, 07:22
thanks for reply but how to resize rectangle with mouse events

anda_skoa
21st December 2015, 08:53
Oh, a double poster.
Don't we love how they waste everone's time?

http://www.qtcentre.org/threads/64608-How-to-Draw-and-resize-Rectangle?p=285658#post285658

Cheers,
_

d_stranz
21st December 2015, 17:07
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.