Results 1 to 3 of 3

Thread: How to draw QCanvasPolygonItem that doesn't change size on zoom? (QT3)

  1. #1
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to draw QCanvasPolygonItem that doesn't change size on zoom? (QT3)

    QT3
    I have a pixmap background in a QCanvas which the user can zoom in to find details in then click on the details to mark them. I draw a QCanvasPolygonItem subclass to mark the spot. I would like the marker to appear the same size as the user zooms in an out.

    Zooming is done in the conventional manner through the QCanvasView using the QWMatrix to zoom (and pan). The normal behavior is for the marker to appear larger when the user zooms in.

    I draw the marker in the drawShape methd of my subclass. How can I work with the world matrix to maintain the same position on the canvas relative to the background but not change size when zooming?

    -- Windflower

  2. #2
    Join Date
    Nov 2006
    Posts
    58
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to draw QCanvasPolygonItem that doesn't change size on zoom? (QT3)

    I have the same problem.
    Is there any possible solution to deal with the problem.
    Thanks a lot.

  3. #3
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Red face Re: How to draw QCanvasPolygonItem that doesn't change size on zoom? (QT3)

    Getting QCanvasItems to work this way is hard; QCanvas indexes items based on their geometry relative to the canvas, and it assumes that items stay the same size regardless of QCanvasView's transformation. Whereas if the item should stay the same size regardless of the transformation, that means the view owns the item's geometry, not the canvas. So QCanvas would claim that items were at one spot, whereas the view would actually render them somewhere else.

    You _can_ make this work, but you need to hijack QCanvasView:aintEvent() and do _all_ the rendering yourself. If you want to interact with the items, you also need to write subtle code in QCanvasView::mouse*Event() handlers. It's very hard to get right, unfortunately. But possible. An easier approach might be to just reimplement QCanvasView:aintEvent() and draw your untransformed shapes directly after calling QCanvasView's base paintEvent implementation.

    Unfortunately, QCanvas doesn't help you a lot in this sense; it simply wasn't designed to support such items.

    [Fyi: In Qt 4, all this trouble is hidden behind a simple flag: QGraphicsItem::ItemIgnoresTransformations. If you set it on an item, the item will remain the same size (w/transformations) regardless of the view. And interaction works like normal.]
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Similar Threads

  1. how to draw a image of size 600x400
    By sar_van81 in forum Qt Programming
    Replies: 2
    Last Post: 12th March 2007, 11:11
  2. change picture size
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 27th November 2006, 18:15
  3. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.