简体   繁体   English

根据QMainWindow的大小调整QWebView和QMessagebox的大小

[英]Resize a QWebView and a QMessagebox according to the QMainWindow's size

I am new to QT. 我是QT新手。 I made an application for Windows which contains a QWebView and a QMessageBox . 我制作了一个Windows应用程序,其中包含QWebViewQMessageBox I want to resize these two according to the size of my QMainwindow . 我想根据QMainwindow的大小来调整这两个大小。 For example, if the main window's size is 300*200 , then the size of QWebView and QMessageBox should be the same. 例如,如果主窗口的大小为300*200 ,则QWebViewQMessageBox的大小应相同。 Plus, I want to be able to resize it when I am running my application. 另外,我希望能够在运行应用程序时调整其大小。

Can someone tell me how to do that? 有人可以告诉我该怎么做吗?

First, I think you should make your QMessageBox and your QWebView children widgets of your QMainWindow . 首先,我认为您应该将QMessageBoxQWebView子控件作为QMainWindow控件。 You should have something like this in your .cpp file : 您的.cpp文件中应该包含以下内容:

MyApp::MyApp(QWidget *parent)
    : QMainWindow(parent)
{
    mView = new QWebView(this);
    mMessageBox = new QMessageBox(this);
    // some other code
}

with mView and mMessageBox private elements of your .h file. .h文件的mViewmMessageBox私有元素。

And for the size, if you don't specify anything, you should be able to resize it as you want. 对于大小,如果您不指定任何内容,则应该可以根据需要调整大小。 Or if you want to try a fixed size, just add this line instead of //some other code : 或者,如果您想尝试固定大小,只需添加此行而不是//some other code

this->setFixedSize(300,200);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM