Issue with showMaximized() and resize() for Fullscreen on Linux
-
Hi,
I am developing an application with Qt, and I’m trying to make the main window start in fullscreen size on Linux. However, even though I use showMaximized() and resize(), the window does not behave as expected. Here are the details:
Code I’m Using:
#include "mainwindow.h" #include <QApplication> #include <QScreen> #include <QGuiApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; // Get screen resolution QScreen *screen = QGuiApplication::primaryScreen(); QRect screenGeometry = screen->geometry(); int screenWidth = screenGeometry.width(); int screenHeight = screenGeometry.height(); // Set window size w.resize(screenWidth, screenHeight); w.show(); return a.exec(); }
Methods I Tried:
Used w.showMaximized(); to maximize the window.
Set the window size manually with resize().
Used QScreen::availableGeometry() instead of QScreen::geometry().
Tried delaying the resizing using a QTimer:QTimer::singleShot(0, [&]() { w.resize(screenWidth, screenHeight); w.show(); });
Attempted a frameless window by using Qt::FramelessWindowHint.
The Problem:
Despite trying all of the above methods, the window does not start in fullscreen. Even with showMaximized(), the window starts in a small size. Could this behavior be caused by GNOME or another window manager? If so, how can I resolve this?Desired Behavior:
I want the window to start in fullscreen size with the title bar and window borders visible (not in frameless mode).I would appreciate any suggestions or solutions.
Thank you!
-
@abdrrhm said in Issue with showMaximized() and resize() for Fullscreen on Linux:
Could this behavior be caused by GNOME or another window manager?
Maybe? It might help if you said whether the GNOME is running under Xorg vs Wayland? (For example, default in Ubuntu 24.x is Wayland now.) I don't know, but if it's Wayland that might not allow full screen or even window sizing/positioning? If you can temporarily change from Wayland to Xorg (like you can under Ubuntu) does that make any difference?