Solved QPixmap increasing size issue
-
Hello All,
I have a qlabel which i am using to display a camera image.void ImageLabel::ShowImage(cv::Mat image) { QImage img = QImage(image.data, image.cols, image.rows, (int) image.step, QImage::Format_RGB888); QPixmap pixmap = QPixmap::fromImage(img).scaled(this->width(),this->height(), Qt::KeepAspectRatio); this->setPixmap(pixmap); this->setBaseSize(pixmap.size()); _logger.LogInfo("QPixmap width= %d height= %d", pixmap.size().width(), pixmap.size().height()); //this->setFixedSize(pixmap.size()); this->repaint(); }
-
My problem is when I call ShowImage(cv::Mat image) function QPixmap size(both height and width) increase by a fixed number. The size of the label keeps on increasing which misplaces the other widgets on the UI form.
-
If use the following : //this->setFixedSize(pixmap.size()); the size of the widget do not crease but i have no idea whether the aspect ratio is maintained.
-
Can anybody let me know why the size of qlabel increases when I call the ShowImage(cv::Mat image) ?
-
-
@Kira said in QPixmap increasing size issue:
this->setBaseSize(pixmap.size());
Is it the same if you comment out this line?
-
Is it the same if you comment out this line?
@jsulm : Yes
-
@jsulm: I was going through the following link :
Resizing QLabel using resizeEvent()
There its mentioned:
It is not advisable to modify the original QPixmap since changing its size modifies the pixels and you will get an unexpected effect.In my case, I am setting pixmap each time. Can this be the reason ?
-
@Kira You're not loading in resizeEvent, right? And you create a new pixmap each time, so I don't think this has any relevance.
-
@jsulm said in QPixmap increasing size issue:
@Kira You're not loading in resizeEvent, right? And you create a new pixmap each time, so I don't think this has any relevance.
No, I am not using any resizeEvent().
-
This post is deleted! -
@jsulm: I the label growing issue is resolved using the following thread
Reszing qlabel issue
Where it mentioned setting the QSizePolicy as ignored. So my doubt is would setting the above property would still maintain my aspect ratio ?? -
@Kira said in QPixmap increasing size issue:
So my doubt is would setting the above property would still maintain my aspect ratio ??
You can just try