PDA

View Full Version : How to fixed the size of the QGraphicsScene.?



syclopse
1st July 2011, 14:38
Hi,

I am having QGraphicsScene in the QGraphicsView,

now what happens is when I set any QPixmap to QGraphicsScene then it will change QGraphicsScene to QPixmap size,

that is not my requirement,
I want to fixed the size of the QGraphicsScene and then image should be adjusted according to QGraphicsScene's size no matter how big an image was.

Please kindly provide me the solution,

high_flyer
1st July 2011, 14:50
see QGraphicsScene::setSceneRect()

syclopse
1st July 2011, 14:53
I have tried it but that will bound the QGraphicsScene's size to minimum means QGraphicsScene will not shrink less then provided,
but QGraphicsScene can take any size maximum than that,
that is not needed in my case,

hope u understand ....

high_flyer
1st July 2011, 15:01
hope u understand ....
am... actually I don't... sorry...

meazza
1st July 2011, 15:05
You could reimplement
QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)

and use the QPainter to draw the QPixmap. Because it looks me to you want the pixmap as background or?

You could even do something like
painter->drawPixmap(0,0, m_backgroundImage.scaled(rect.width(), rect.height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

syclopse
2nd July 2011, 12:00
when I am using

painter->drawPixmap(0,0, m_backgroundImage.scaled(rect.width(), rect.height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

I am getting the error that painter is not active.
please guide me

meazza
4th July 2011, 11:34
Try calling QPainter::begin() and QPainter::end(). http://doc.qt.nokia.com/latest/qpainter.html#begin

syclopse
4th July 2011, 12:09
I am using QPainter::begin() and QPainter::end().
dude .... !!!!

SixDegrees
4th July 2011, 14:12
Then your code is wrong.

syclopse
4th July 2011, 14:41
Actually I am using QPainter outside of paintevent().