Results 1 to 4 of 4

Thread: temporal shapes in drawing application

  1. #1
    Join Date
    Jul 2009
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default temporal shapes in drawing application

    Hi.
    I'm making a drawing app and i want to be able to draw lines, rectangles, ellipses ,...
    I've think making like this:
    1- Save the starting point
    Qt Code:
    1. void mousePressEvent(QMouseEvent *event);
    To copy to clipboard, switch view to plain text mode 
    2- Draw temporal shape based on the type of cursor
    Qt Code:
    1. void mouseMoveEvent(QMouseEvent *event);
    To copy to clipboard, switch view to plain text mode 
    3- Finish the draw and add it to the scene
    Qt Code:
    1. void mouseReleaseEvent(QMouseEvent *event);
    To copy to clipboard, switch view to plain text mode 


    But i don't know how to make the second step, drawing the temporal shape (rectangle, circle, line, ...) while the user has the button pressed until it's released.

    Some ideas?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: temporal shapes in drawing application

    You have to develop logic for them, there is no ready to eat pasta.
    Play with these 3 events and you will get what you want.
    For rectangle you can use this logic.
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. origin = event->pos();
    4. if (!rubberBand)
    5. rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
    6. rubberBand->setGeometry(QRect(origin, QSize()));
    7. rubberBand->show();
    8. }
    9.  
    10. void Widget::mouseMoveEvent(QMouseEvent *event)
    11. {
    12. rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
    13. }
    14.  
    15. void Widget::mouseReleaseEvent(QMouseEvent *event)
    16. {
    17. rubberBand->hide();
    18. // determine selection, for example using QRect::intersects()
    19. // and QRect::contains().
    20. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: temporal shapes in drawing application

    Thank you but this is useful only for one line or one rectangle, but not for more complex shapes like polylines or ellipses.

    I think that i'll create a widget like a rubberband but a little more complex, and i'll use it the same way as you with the rubberband.

    Others ideas?

    Quote Originally Posted by yogeshgokul View Post
    You have to develop logic for them, there is no ready to eat pasta.
    Play with these 3 events and you will get what you want.
    For rectangle you can use this logic.
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. origin = event->pos();
    4. if (!rubberBand)
    5. rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
    6. rubberBand->setGeometry(QRect(origin, QSize()));
    7. rubberBand->show();
    8. }
    9.  
    10. void Widget::mouseMoveEvent(QMouseEvent *event)
    11. {
    12. rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
    13. }
    14.  
    15. void Widget::mouseReleaseEvent(QMouseEvent *event)
    16. {
    17. rubberBand->hide();
    18. // determine selection, for example using QRect::intersects()
    19. // and QRect::contains().
    20. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: temporal shapes in drawing application

    Quote Originally Posted by parnedo View Post
    Thank you but this is useful only for one line or one rectangle,
    That I already mentioned, this is only for rectangle.

    Quote Originally Posted by parnedo View Post
    but not for more complex shapes like polylines or ellipses.
    This is true.

    Quote Originally Posted by parnedo View Post
    Others ideas?
    What ideas, now you just go ahead, develop logic for how to draw a eclipse and all. I think now you dont have any Qt code related question.

Similar Threads

  1. Drawing and resizing shapes
    By jonnale in forum Qt Programming
    Replies: 10
    Last Post: 15th April 2020, 16:44
  2. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  3. Replies: 3
    Last Post: 3rd March 2009, 12:24
  4. Drawing shapes
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 31st October 2008, 09:19
  5. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37

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.