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
setGeometry: Unable to set geometry 22x22+320+145 on QWidgetWindow/'WidgetClassWindow'. Resulting geometry:  116x22+320+145 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 22x22, maximum size: 16777215x16777215).

The project is:

project.pro

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled5
TEMPLATE = app
SOURCES += main.cpp\
        widget.cpp
HEADERS  += widget.h

widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
    Q_OBJECT
public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
private:
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include <QVBoxLayout>
Widget::Widget(QWidget *parent) :
    QWidget(parent)
    QVBoxLayout *vLayout = new QVBoxLayout(this);
Widget::~Widget()

main.cpp

#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();

Adding setGeometry(0, 0, 400, 300); in Widget constructor removes the issue. But the window will not be positioned beautifully at the center of the screen.

This warning happens (at least to me) when the size of the widget results to be very small.

Set a minimum size for your widget (so it will be automatically positioned), like:

 // Widget constructor
 QVBoxLayout* vLayout = new QVBoxLayout();
 setLayout(vLayout);
 setMinimumSize(200,200);

You should also parent your widget to a QMainWindow, but will still work.

thanks a lot.. I was missing to set the parent for a ComboBox widget and your solution helped.. – sundar Jul 22, 2015 at 18:28 It worked very well directly on the main.cpp where I instantiated MainWindow: mainWindow.setMinimumSize(200, 200);. – Patapoom Sep 24, 2019 at 14:43 Worked for my dialog box ! strange I never had this problem with Linux, I encountered it with Windows. – Aminos May 21, 2021 at 9:14 It kind of worked for my dialog box. I just set minimum sizes for width and height on QT Designer. – Cem Polat May 12, 2022 at 10:24

Try to use: ajustSize()

Looks To be the problem: Why am I getting QWindowsWindow::setGeometry: Unable to set geometry warning with Qt 5.12.0

A possible solution: Qt Unable to set geometry

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.