【发布时间】:2019-01-22 11:35:44
【问题描述】:
我将一些代码从 Qt 5.6.0 迁移到 5.12.0。令人惊讶的是,我收到了很多与QWindowsWindow::setGeometry 相关的警告。每当一个对话框显示在另一个对话框之上时,我都会收到此警告。
我可以将问题隔离在 MCVE 中,它非常简单且极简,所有育儿看起来都不错,但是,当按下按钮时我们会收到警告:
QWindowsWindow::setGeometry: Unable to set geometry 132x30+682+303 on QWidgetWindow/'QDialogClassWindow'. Resulting geometry: 132x42+682+303 (frame: 4, 28, 4, 4, custom margin: 0, 0, 0, 0, minimum size: 116x42, maximum size: 16777215x16777215).
main.cpp:
#include <QApplication>
#include "mainframe.h"
#include <qDebug>
void MessageOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
qDebug() << msg;
}
int main( int argc, char* argv[] )
{
QApplication app(argc, argv);
qInstallMessageHandler(MessageOutput);
MainFrame wnd;
wnd.show();
return app.exec();
}
mainframe.h:
#include <QMainWindow>
class QPushButton;
class MainFrame : public QMainWindow
{
Q_OBJECT
public:
MainFrame();
public slots:
void showPopup();
private:
QPushButton* button;
};
mainframe.cpp:
#include "mainframe.h"
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
MainFrame::MainFrame()
{
QWidget* widget = new QWidget( this );
widget->setLayout( new QVBoxLayout( widget ) );
QPushButton* pTextButton = new QPushButton( "Show popup", widget );
widget->layout()->addWidget( pTextButton );
connect( pTextButton, SIGNAL(clicked()), this, SLOT(showPopup()) );
setCentralWidget( widget );
}
void MainFrame::showPopup()
{
QDialog dlg( this );
dlg.setLayout( new QVBoxLayout() );
dlg.layout()->addWidget( new QLabel("popup message",&dlg) );
dlg.exec();
}
我在 Windows 7 和 10 下看到了这个问题。我做错了什么吗?
我知道可以通过设置setMinimumSize(参见https://stackoverflow.com/a/31231069/3336423)来删除警告,但是为什么我们要对我们创建的每个小部件都这样做呢?有没有办法永久解决这个问题?
【问题讨论】: