Results 1 to 9 of 9

Thread: Advice on how to implement a rotating and zooming drawing canvas

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

    Question Advice on how to implement a rotating and zooming drawing canvas

    Hi, I been doing a lot of study on Qt but haven't programmed a line yet, because Im researching for the best approach for my first Qt program.

    I want a build a drawing software and want some advice for the best aproach. I already studied the scribble and tablet examples so I know how to build the drawing Widget, the thing is that I need it to zoom and rotate with the mouse.

    The approach I was thinking of is to set up a scene, and put the canvas widget in it, then set up a view window with the proper events to rotate and zoom the scene.

    The other aproach I thought is to do the canvas Widget alone, program a white drawing area, and set up drawing restraints so the brush strokes won't go out of the canvas.

    What do you guys think?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    It's fine. Just to confirm something - implement it using Graphics View.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    ruakuu (2nd October 2009)

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

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Quote Originally Posted by wysota View Post
    It's fine. Just to confirm something - implement it using Graphics View.
    Thanks, yeah, Graphics View is what I had in mind for the first approach:
    - Create a canvas widget derived from QWidget
    - Define a scene (QGraphicsScene)
    - Put the canvas widget in the scene (QGraphicsScene::addWidget())
    - Define a View (QGraphicsView) and rotate scene with it

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Quote Originally Posted by ruakuu View Post
    - Create a canvas widget derived from QWidget
    Hold on! What do you want to do that for? Scene is your canvas, you don't need any extra widgets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Oh, you mean I can paint(draw) directly in the scene with the mouse or tablet? As far as I know, you could only do that with classes derived from QPaintDevice, you can add items to the scene but not draw directly in it, that is what I readed in the documentation, or am I missing something here?

    Unless Im not explaining myself correctly, I want to actually use the mouse or tablet to scketch there.

    I was going to make a class derived from QWidget (also using QImage for loading images), to make me a drawing canvas Widget, then put that in the scene and rotate it with a view. I saw this canvas approach in the Scribble and Tablet examples that comes with Qt. Both make a canvas that derives from QWidget.

    I want to make something like the little japanese program called Opencanvas.
    Last edited by ruakuu; 2nd October 2009 at 18:25.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Quote Originally Posted by ruakuu View Post
    As far as I know, you could only do that with classes derived from QPaintDevice, you can add items to the scene but not draw directly in it, that is what I readed in the documentation, or am I missing something here?
    You can add your scribbling as items to the scene. You'd have to do it when subclassing QWidget too, just without any dedicated infrastructure.

    I was going to make a class derived from QWidget (also using QImage for loading images), to make me a drawing canvas Widget, then put that in the scene and rotate it with a view. I saw this canvas approach in the Scribble and Tablet examples that comes with Qt.
    And how would your paintEvent() for the widget look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Quote Originally Posted by wysota View Post
    And how would your paintEvent() for the widget look like?
    For now it will look like this:

    Qt Code:
    1. void MyCanvas::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.drawImage(QPoint(0, 0), image);
    5. }
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    After looking at the Pencil animation software I will implement a better aproach, since this is going to be an animation software too.

    Rather than use graphic views Im just us a QMatrix on the widget to do the transforms and a combination QPixmap and QImage for the temp image storing. All this because of performance.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advice on how to implement a rotating and zooming drawing canvas

    Quote Originally Posted by ruakuu View Post
    Qt Code:
    1. void MyCanvas::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.drawImage(QPoint(0, 0), image);
    5. }
    To copy to clipboard, switch view to plain text mode 
    And how do you create the image? So far your widget is equivalent to QGraphicsPixmapItem. What about providing undo/redo functionality?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.