Results 1 to 11 of 11

Thread: Drawing and resizing shapes

  1. #1
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drawing and resizing shapes

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drawing and resizing shapes

    I would suggest taking a look at the graphics view framework.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    jonnale (23rd January 2009)

  4. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drawing and resizing shapes

    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.

  5. #4
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing and resizing shapes

    Quote Originally Posted by jpn View Post
    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!

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drawing and resizing shapes

    I would use a movable child item. Here's something to get you started:
    Attached Files Attached Files
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    jonnale (23rd January 2009)

  8. #6
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing and resizing shapes

    Awesome! That will be a great start. Thank you so much!

  9. #7
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing and resizing shapes

    Quote Originally Posted by jpn View Post
    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)

  10. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drawing and resizing shapes

    Quote Originally Posted by jonnale View Post
    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.
    Attached Files Attached Files
    J-P Nurmi

  11. The following 2 users say thank you to jpn for this useful post:

    Basser (29th July 2010), jonnale (25th January 2009)

  12. #9
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing and resizing shapes

    Quote Originally Posted by jpn View Post
    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)

  13. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drawing and resizing shapes

    Quote Originally Posted by jonnale View Post
    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.
    J-P Nurmi

  14. #11
    Join Date
    Apr 2020
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Drawing and resizing shapes

    I know this is a 11 year old thread but how did you implement a circle shape into the handles?

Similar Threads

  1. Drawing shapes
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 31st October 2008, 09:19

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.