PDA

View Full Version : Resizing QGraphicsScene to fit entire contents of QGraphicsScene



mgoldman
4th September 2012, 21:33
Hi,

I have a program which parses through a .txt file containing photo pathnames and then adds them as QGraphicsPixmapItems to a QGraphicsScene. This works correctly but I am unable to get the QGraphicsView to resize to the size of the pixmap so that the whole image is visible.

To do this, I have created a class TrainingDataWindow which subclasses QMainWindow. The class contains a function selectImageSource() that correctly obtains the first pixmap from the .txt file and adds it to the QGraphicsScene. In this function, I have tried multiple ways of calling QGraphicsView::resize(....) in order to make the whole image visible. These methods include:

1.

view_image->resize(imgScene.itemsBoundingRect().width(),imgSce ne.itemsBoundingRect().height());

2.


QSize imgSize = img.size();
view_image->resize(imgSize);


where view_image is of type QGraphicsView and img is of type QPixmap. Neither of these (or others) have done anything (literally).

Any ideas on how to fix this? If i do need to reimplement resizeEvent() for the TrainingDataWindow class how would this be affected since I designed the program with Qt Designer?

Thanks,
Max

wysota
8th September 2012, 05:08
QGraphicsView::fitInView()