I've read the documentation of Qt for resizing policy but I couldn't find how can I achieve the scenario of changing the image's size to fit the new size of Qlabel.
This is my GUI structure
mainLayout:
toplayout:
QLabel
QPushButton
Now I have cv::Mat
image. I have converted to QPixmap
.
Window::Window(QWidget *parent): QDialog(parent)
{
// Widgets
browserButton = new QPushButton(tr("Open"));
imageLabel = new QLabel;
imageLabel->setAlignment(Qt::AlignHCenter);
imageLabel->setScaledContents(true);
// Connect Actions
connect(browserButton, SIGNAL(clicked()), this, SLOT(browserClicked()));
// Layouts
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(imageLabel);
topLayout->addWidget(browserButton);
// Main Layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
setLayout(mainLayout);
setWindowTitle("Image Browser");
}
This is the button
void Window::browserClicked()
{
// Get file name as QString
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"),
NULL,
tr("Image Files (*.png *.jpeg *.jpg *.bmp)"));
// Read file name as String not QString and store the image
m_original_CVimg = cv::imread(fileName.toStdString());
imageLabel->setPixmap(this->cvMatToQPixmap(m_original_CVimg));
}
I want to resize the image's size every time the user changes the size of the window. If I expand the window, the image also is expanded but the problem if I shrink the window, the size of the window is restricted to the size of the image. Any suggestions