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?
-
@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 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