[英]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应用程序,其中包含
QWebView
和QMessageBox
。 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
,则QWebView
和QMessageBox
的大小应相同。 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
. 首先,我认为您应该将
QMessageBox
和QWebView
子控件作为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
文件的mView
和mMessageBox
私有元素。
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.