Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with showMaximized() and resize() for Fullscreen on Linux
Forum Updated to NodeBB v4.3 + New Features

Issue with showMaximized() and resize() for Fullscreen on Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 238 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abdrrhm
    wrote on last edited by
    #1

    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!

    JonBJ 1 Reply Last reply
    0
    • A abdrrhm

      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!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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?

      A 1 Reply Last reply
      0
      • JonBJ JonB

        @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?

        A Offline
        A Offline
        abdrrhm
        wrote on last edited by
        #3

        @JonB Thank you very much for your answer. I tried your answer and it worked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved