Results 1 to 15 of 15

Thread: Qt Coordinate System and the Graphics View Framework

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Location
    Slovenia
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Coordinate System and the Graphics View Framework

    Quote Originally Posted by djurodrljaca View Post
    Well this solves the problem. Now all I have to do is use scale(1, -1) on all QGraphicsItems and on the QGraphicsView and I get the real Cartesian coordinate system...
    I was wrong again. All shape items are OK, since they are "immune" to "mirroring", the only problem are the items that include text. In this items you only have to mirror the text.
    ("immune" means that the shape is at the right location and rotation only when you scale the view)

    To sum things up:
    All I have to do is use scale(1, -1) on all QGraphicsTextItems (and QGraphicsSimpleTextItems) and on the QGraphicsView and then you get the real Cartesian coordinate system...

    I hope this helps someone...

  2. #2
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt Coordinate System and the Graphics View Framework

    Quote Originally Posted by djurodrljaca View Post
    I hope this helps someone...
    Damn, I spent almost a month getting the coordinate system right and Im looking at this post now!
    (...bangs his head TOO against the wall really really hard...)

    BUT, I have one more HUGE problem.
    I am working on a map utility, similar to Google Maps (Not that extensive though.) I have used scale(1,-1) for getting the coordinate system right, just the way djurodrljaca has done. I am using picture (svg files) to represent cities and other prominent places on the map. When I draw these pictures using QGraphicsPixmapItem, I have explicitly used pixmapItem->scale(1,-1); to bring it back to normal. BUT now, when I zoom on to the view, the picture is also zoomable, i.e. it gets bigger and bigger, something that is undesirable. So I used the qt flag QGraphicsItem::ItemIgnoresTransformations. But then the result is just not visible. And if I change the implementation a little, it remains constant in size regardless of the zoom level, but is again mirrored!
    Similarly, I am using QGraphicsTextItem for showing labels for cities on the map and when I use this flag, QGraphicsItem::ItemIgnoresTransformations, on it, with scale(1,-1), the result is just the same...

    Please suggest something. I have already spent a lot of time getting this thing right and I am still nowhere near it

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

    Default Re: Qt Coordinate System and the Graphics View Framework

    Did you try setting an inverted rectangle (starting from negative vertical values and ending at 0 or starting at positive vertical value and ending at 0 or negative) as the scene rect? This way you wouldn't have to scale anything.

  4. #4
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt Coordinate System and the Graphics View Framework

    Hey, thanks for that reply. N my apologies for replying back late ...
    Well, if I invert the scene rectangle, all my points, lines and polygon shapes drawn on it get inverted too. By scaling the view scale(1,-1) I get what I want, like showing proper coordinates on the screen, except only for QGraphicsPixmapItem and QGraphicsTextItem (They get drawn inverted).
    The kludge that I adopted worked for me. I transformed the pixmap used in QGraphicsPixmapItem using QTransform. So now it is shown properly onto the canvas. BUT, if i use QGraphicsItem::ItemIgnoresTransformations flag (To keep the picture from changin when the zoom level is changed), the picture just disappears! I dont know why and I have not been able to solve this issue as well...

    Is there something wrong with the coordinate system (s) set for scene, view and/or the items in Qt???

  5. #5

    Default Re: Qt Coordinate System and the Graphics View Framework

    has anyone managed to figure out if there is a good way to rotate/translate the coordinate system so that when drawing angles, zero degrees is up and value increase clockwise instead of zero degrees to the right and values increase counter-clockwise?

  6. #6
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: Qt Coordinate System and the Graphics View Framework

    I have found the solution.
    Use a QGraphicsItemGroup to contain the text items. Use the group to set coords, scales and rotation. The text items ignores the transformations.
    For example:

    Qt Code:
    1. grp->addToGroup(text);
    2. text->setFont(font);
    3. text->setPos(0,0);
    4. text->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    5. grp->setPos(x,y);
    To copy to clipboard, switch view to plain text mode 


    Pay attention that the text item must be added to group before his setting his coordinates, since coordinates of the sub-item are relative to the parent item, BUT when adding the item to the group his coords relative to the scene are preserved.

    Hope that helps.

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
  •  
Qt is a trademark of The Qt Company.