PDA

View Full Version : Graphics view coordinates - am I stupid or what?



Miihkali
23rd May 2009, 18:13
I posted this originally into the programming forum, but I think it belongs here...

I'm confused with the graphics view framework coordinate system. There is so much information about all kinds of conversions, relations, mappings etc. that I haven't been able to find out solution to my trivial problem.

The problem is: I want to draw my item so that it fills the view completely. How can I do this after I've scrolled the view? I don't want to use QGraphicsView::fitInView(), I just need to tell in my item's paint function that draw yourself and fill the whole view while doing it.

wysota
23rd May 2009, 19:33
If you want an item covering the whole view, it might be better if you don't use Graphics View at all but instead implement a custom widget.

But to answer your question - you have to be aware that the size of the view doesn't really matter. What matters is the size of the scene. What I understand you want to scroll the view and still have the item filling the view totally. You need to know the size of the viewport() of the view and you need to set your item to that size by modifying its QGraphicsItem::boundingRect(). Of course if you resize the view, you'll have to modify the bounding rect of the item too. QWidget::resizeEvent() will be helpful for that.

Miihkali
26th May 2009, 07:29
All righty, thanks for clarifications!

I'm using graphics view because I need to have multiple graphic items that can be handled easily. I don't know if that is the best option, but as I'm fairly new to Qt it seemed to be logical choice.

I'm developing an image viewer software, where there are several thumbnails (QGraphicItems) spread around the graphics view. When I doubleclick a thumbnail, it's opened as "full-size" image, i.e. it fills the whole viewable area. (what is the correct term for this? viewport? I'll use that until someone proves me wrong =)

The problem was that in some occasions when I enlarge a thumbnail, it's drawn a bit off the viewport. I want that in every occasion the top left corner of the enlarged image is in the top left corner of the viewport.

Sorry for the longish explanation, hopefully it clarified this a bit.

wysota
26th May 2009, 21:12
Consider using QStackedWidget with a QLabel and QPixmap representing the "full" view and QGraphicsView representing the thumbnail view.