我正在尝试显示图像,当我调整窗口大小时,我希望图像随之调整大小。但是,当窗口打开时,它会以完整尺寸显示图像,但是我无法调整窗口大小。我在做什么错了?
以下是代码:
ui.setupUi(this);
Mat imgMat;
reader >> frameMat;
cvtColor(imgMat, imgMat, CV_BGR2RGB);
QImage qImg(imgMat.data, imgMat.cols, imgMat.rows, imgMat.step, QImage::Format_RGB888);
ui.videoFrameLabel->setPixmap(QPixmap::fromImage(qImg));
ui.videoFrameLabel->setScaledContents(true);
ui_MyAppliction.h
/********************************************************************************
** Form generated from reading UI file 'MyApplication.ui'
**
** Created by: Qt User Interface Compiler version 5.12.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MyApplication_H
#define UI_MyApplication_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MyApplicationClass
{
public:
QWidget *centralWidget;
QVBoxLayout *verticalLayout;
QLabel *videoFrameLabel;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MyApplicationClass)
{
if (MyApplicationClass->objectName().isEmpty())
MyApplicationClass->setObjectName(QString::fromUtf8("MyApplicationClass"));
MyApplicationClass->resize(695, 464);
centralWidget = new QWidget(MyApplicationClass);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
verticalLayout = new QVBoxLayout(centralWidget);
verticalLayout->setSpacing(6);
verticalLayout->setContentsMargins(11, 11, 11, 11);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
videoFrameLabel = new QLabel(centralWidget);
videoFrameLabel->setObjectName(QString::fromUtf8("videoFrameLabel"));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(videoFrameLabel->sizePolicy().hasHeightForWidth());
videoFrameLabel->setSizePolicy(sizePolicy);
verticalLayout->addWidget(videoFrameLabel);
MyApplicationClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MyApplicationClass);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 695, 21));
MyApplicationClass->setMenuBar(menuBar);
mainToolBar = new QToolBar(MyApplicationClass);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MyApplicationClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MyApplicationClass);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MyApplicationClass->setStatusBar(statusBar);
retranslateUi(MyApplicationClass);
QMetaObject::connectSlotsByName(MyApplicationClass);
} // setupUi
void retranslateUi(QMainWindow *MyApplicationClass)
{
MyApplicationClass->setWindowTitle(QApplication::translate("MyApplicationClass", "MyApplication", nullptr));
videoFrameLabel->setText(QString());
} // retranslateUi
};
namespace Ui {
class MyApplicationClass: public Ui_MyApplicationClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MyApplication_H