Почему я не могу изменить размер окна с его содержимым в Qt? - PullRequest
0 голосов
/ 18 апреля 2019

Я пытаюсь показать изображение, и когда я изменяю размер окна, я хотел бы, чтобы изображение было изменено с ним.Но, когда окно открывается, оно показывает изображение в полном размере, но я не могу изменить размер окна.Что я делаю не так?

Вот код:

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...