My work Environment: Qt 5.8 MSVC2015 64bit, QT GraphicsView, QGraphicsObject, Windows 7 64 bit.
I am loading image of any Size using QImage, try fit into QGraphicsView of fix size (Width 200 X Height 200). I don't want scrollbar in QGraphicsView.
In below example :
- My QGraphicsView size will be always fix Width 200 X Height 200.
- My Image size will may vary, but in below code my image Width 182 * Height 174.
So how I can any fit Image in a fix size QGraphicsView ?
QImage *ImageData;
QGraphicsView* _ThumbNailView = new QGraphicsView(this);
_ThumbNailView->setFixedSize(200, 200); //QGraphicsView will be alwyas constant.
QGraphicsScene* _scene = new QGraphicsScene();
_scene->setSceneRect(0,0,200,200);
..........
myQGraphicsItem* _thumbsquare = new myQGraphicsItem(imageWidth, imageHeight, ImageData);
//Load image from buffer
unsigned char *buffer; ////some image Data get loaded here.
int imageWidth = 182; //I am getting image Width 182, or any size.
int imageHeight = 174; //I am getting image Height 174 or any size.
size_t size = imageWidth * imageHeight * 3;
int bytesPerLine = size / imageHeight;
QImage* _image = new QImage(reinterpret_cast<const uchar *>(buffer),182, 174, bytesPerLine, QImage::Format_RGB888);
_thumbsquare->setMyImage(QImage);
...........
int width = _ThumbNailView->geometry().width(); // always const 200
int height = _ThumbNailView->geometry().height(); // always const 200
_ThumbNailView->resize(width, height);
_scene->addItem(_thumbsquare);
_scene->setSceneRect(_scene->itemsBoundingRect());
// This don't work, make image very small
//_ThumbNailView->fitInView(QRectF(0, 0, 200, 200));
Above code result
Expected Full Fit Image without Scroll bar
Any suggestion or help is highly appreciated ?