PDA

View Full Version : Drawing and resizing shapes



jonnale
23rd January 2009, 02:38
Hello everyone,

I have been working with Qt for the past 3 or 4 months, but have never done anything that required drawing. I am now starting a project (for fun) which requires drawing and have a few questions.

Before I tackle the project, I want to play around with the basics. Here is what I want my pre-project program to do:

1.) User clicks "circle" button.
2.) User moves mouse over draw area
3.) User clicks and holds, and moves mouse to determine size of circle
4.) User releases mouse and circle is drawn

I would also like the user to be able to resize the circle after it has been drawn:
1.) User clicks circle
2.) Resize handles appear
3.) User clicks and drag resize handle to change size of circle

Now for this, I realize I need to use the mouse move event, however, my bigger problem is the resize handles. Would I have make a custom circle widget that has resize handles, or is their a built in method that can be used for displaying them? I know windows have a a QSizeGrip, but I am not sure how I would incorporate this into a widget.

Any help is greatly appreciated. Thank you!!
Jon

jpn
23rd January 2009, 13:28
I would suggest taking a look at the graphics view framework.

xgoan
23rd January 2009, 15:33
I have the same problem, and I have already looked in the documentation, but I have no idea of how can do this in a simple way.

jonnale
23rd January 2009, 17:19
I would suggest taking a look at the graphics view framework.

Thank you very much for this.

It seems like I will have to use a variety of methods, and ultimately use the transform() method to resize the item.

For the resize handles, I am still not positive, but it looks like I will use the bounding rectangle? This will probably work, but I am assuming it won't have the exact look I am aiming for (I like when the size grips have the little rectangles in the corners).

If anyone has any other suggestions that would be great!

jpn
23rd January 2009, 20:38
I would use a movable child item. Here's something to get you started:

jonnale
23rd January 2009, 22:41
Awesome! That will be a great start. Thank you so much!

jonnale
23rd January 2009, 23:16
I would use a movable child item. Here's something to get you started:

Just out of curiosity, how come if I reverse everything, and put the bounding rect in the bottom left corner, when resizing the square, the size of the square goes crazy? (Having it in the bottom right is fine, I am just curious more than anything)

jpn
24th January 2009, 22:53
Just out of curiosity, how come if I reverse everything, and put the bounding rect in the bottom left corner, when resizing the square, the size of the square goes crazy? (Having it in the bottom right is fine, I am just curious more than anything)
Ok, looks like it was a bad idea to use ItemIsMovable flag for the resize handle. Here's a revised example with all eight resize handles.

jonnale
25th January 2009, 21:08
Ok, looks like it was a bad idea to use ItemIsMovable flag for the resize handle. Here's a revised example with all eight resize handles.

This is fantastic!

I am using these handles on a circle, and I am only using the outer 4 handles. I also added a simple check so that when the user is resizing the circle, when the user drags the handle it retains the shape of a circle.

My only other question is, I noticed that when you resize the circle to a size larger than any previous size, it moves the entire circle. I.e. if you drag the bottom right corner and make it larger, it will move the top as well. How could you get it so that the only corner that moves is the corner you are dragging (i.e. the top left of the rectangle will stay exactly where it is, and the bottom right and other edges that the drag affects, move,)?

(I actually like the way it is currently adjusting the size, this is just out of curiosity)

jpn
25th January 2009, 21:36
My only other question is, I noticed that when you resize the circle to a size larger than any previous size, it moves the entire circle. I.e. if you drag the bottom right corner and make it larger, it will move the top as well. How could you get it so that the only corner that moves is the corner you are dragging (i.e. the top left of the rectangle will stay exactly where it is, and the bottom right and other edges that the drag affects, move,)?
This happens because no "scene rect" has been set explicitly (so it will grow automatically to fit items) and the default alignment of graphics view is centered. So, you could either set a suitable scene rect and/or you could change the alignment of the view.

xd123
15th April 2020, 17:44
I know this is a 11 year old thread but how did you implement a circle shape into the handles?