Important: Please read the Qt Code of Conduct -

Mainwindow offcenter in linux

  • I have a situation where my main window opens in the upper left of the monitor, only under linux. It looks quite strange, especially when a informational popup appears at program start, that is properly centered where mainwindow is on Mac and Windows! Screenshot below:

    How can I fix this Linux issue?

  • I am not sure how you center your window so I have no suggestions.

    I don't center the window but store the last size and location in a settings file. I use the following in the constructor:

    Position = d_Settings->value("Mainwindow_Position", QPoint(30,30)).toPoint();
    Size = d_Settings->value("Mainwindow_Size", QSize(800, 509)).toSize();

    DesktopRect = QApplication::desktop()->availableGeometry();


    WidgetRect = WidgetRect & DesktopRect;

    this->resize(QSize(800, 509));

    The intersected() function '&' makes sure the window is not off the desktop (somewhere you can't get to it).

  • Interesting, thank you!

Log in to reply