PDA

View Full Version : QGraphicsView\Scene drawBackground bitmap as geomap



pethead
29th October 2010, 05:46
have some code..

declaration
QPixmap map;
QGraphicsView

in MainWin construct
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->centerOn(0,0);// after it tha map is drawing to 0,0 on left,top on the scene

but if move the scrolls then map is spoiled and repaint to left,top of visible area of QGraphicsView

I need to paint map to 0,0 always.



NetView::NetView(QGraphicsScene *scene, QWidget *parent)
: QGraphicsView(scene, parent)
{
QString name = "C:/MAP1.bmp";
map.load(name);
}

void NetView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->drawPixmap(rect.left(),rect.top(),map);
}

if I override Scene::drawBackground effect is the same.

I made painting map as brush:
view->setBackgroundBrush(QPixmap("C:/RUSMAP1.bmp"));
it's cool and working great but map is tiled :) I need one tile in the left,top corner

pethead
29th October 2010, 13:45
found solutuon:

void cene::drawBackground(QPainter *painter, const QRectF &rect)
{
int w=img.width();
int h=img.height();
QRectF r;
r.setRect(0,0,w,h);

painter->drawImage(r,img);
}