View Full Version : Graphics View and the Pixmap

22nd June 2009, 22:36
Hello all,

I have read some interesting things about QGraphicsView and how to add items and pixmaps. I have not see this exact issue tackled...

I have a main view, QGraphicsView subclass, and I have a secondary view which is also a subclass of the graphics view. I have a scene that changes and has selectable items on it; So what I need is for the secondary view to act as a mini map. This mini map is supposed to have a 'picture' of the main view's scene (background image) and a rectangle that represents the view area of the main view. The rectangle is attached to the view such that moving the main view will move the rectangle in the secondary view and vice versa.
I have everything taken care of and works like I want it except I cannot get the image to display in the mini map. I have tried setting the background but cannot find a way to make the background show 1 solid image; I also, have tried adding a pixmap but because I set the bounding Rect on both scenes when I add the pixmap it is too small to be of use.

Example scene coordinates, because of the data I'm using, are on the order of 600,000 and dimensions are 7000-16000.

Now the view itself is only of size 290x180 or something like that; so I don't think the pixmap should need to be so large.

I know the coordinate system is my nemesis!! :mad:

The question... how to get my pixmap (pixmapgraphicsitem) to fill the view?

sw developer (first go at Qt)

22nd June 2009, 22:55
I suggest you override QGraphicsView::drawBackground to draw the image.

26th June 2009, 23:12
Thank you for your response. I had tried this already but as I am new to Qt, it seems I needed a few more days (and attempts) to understand how to do this.
I used painter's dwarPixmap function and found that a simple rectangle of the basemap scene and the pixmap did the trick.

QPainter::drawPixmap(const QRect& ,const QPixmap &)

sw developer