相关文章推荐
笑点低的机器猫  ·  shell 中的 set -e ...·  3 周前    · 
温暖的饭卡  ·  ls mac ...·  1 月前    · 
精明的冲锋衣  ·  C sharp 将object ...·  1 月前    · 
任性的大脸猫  ·  React ...·  4 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Why am I getting QWindowsWindow::setGeometry: Unable to set geometry warning with Qt 5.12.0

Ask Question

I migrated some code from Qt 5.6.0 to 5.12.0. Suprisingly, I'm getting lots of warnings related to QWindowsWindow::setGeometry . Whenever a dialog is shown on top of another, I get this warning.

I could isolate the problem in a MCVE, it's very simple and minimal, all parenting look good, however, we get the warning when button is pressed:

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();

I see the issue under Windows 7 and 10. Am I doing anything wrong?

I know the warning can be removed by setting setMinimumSize (see https://stackoverflow.com/a/31231069/3336423), but why should we do this for every widget we create? Is there a way to fix that for good?

As you mentioned, this problem occurs only in Windows: the QWindowsWindow class is part of the windows platform plugin. Looking at Qt's source code (qwindowswindow.cpp@QWindowsWindow::setGeometry) there is no direct way to pause that specific message.

The only global solution I can think of right now is to filter the warning messages using a message handler:

void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
  if (type != QtWarningMsg || !msg.startsWith("QWindowsWindow::setGeometry")) {
    QByteArray localMsg = msg.toLocal8Bit();
    fprintf(stdout, localMsg.constData());
int main(int argc, char* argv[])
  qInstallMessageHandler(myMessageOutput);
  QApplication a(argc, argv);
  // ...

UPDATE

One of the problems is that Windows adds its own buttons to the frame. In your example the dialog adds three buttons: the system button (the icon, top-left corner), the help button and the close button. The help and close buttons have a fixed size, which happens to be larger than the QDialog's frame (which is computed as the maximum between the requested size and minimumSize). This then generates the warning: your requested size doesn't match the one created by Windows:

If you remove the help button, for example (dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);), the warning disappears without setting a minimum size for the window. A manual action must be taken for each dialog displayed, but I think it is easier to automatize than the minimum size (through a factory maybe?):

@jpo38 I've added a bit more information about it that may help you. I don't think a global fix exists. – cbuchart Jan 22, 2019 at 14:48

The issue was reported to Qt: https://bugreports.qt.io/browse/QTBUG-73258

To the code in OP is OK, it's just a Qt bug.

It's marked as "P2 Important", so hopefully it should be fixed in a next release.

Update: It's still not fixed in Qt 6.2.2...

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.