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. QDialog Showmaximized not working
QtWS25 Last Chance

QDialog Showmaximized not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 922 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.
  • S Offline
    S Offline
    Seb Tur
    wrote on 8 Aug 2023, 13:34 last edited by
    #1

    After days of research I found that the bug is still there almost 10 years after report.
    This is important for anybody using QinputDialog Ubuntu (I tested on Ubuntu 22.04) : showMaximized() and showNormal() have issues changing the state. This makes setGeometry troublesome as well.

    https://bugreports.qt.io/browse/QTBUG-16034

    I spend hours searching this forum and others finally finding the bug report.

    So if moderators allow let's have it here for record of others searching for the cause.

    J 1 Reply Last reply 8 Aug 2023, 14:09
    0
    • S Seb Tur has marked this topic as solved on 8 Aug 2023, 13:34
    • S Seb Tur
      8 Aug 2023, 13:34

      After days of research I found that the bug is still there almost 10 years after report.
      This is important for anybody using QinputDialog Ubuntu (I tested on Ubuntu 22.04) : showMaximized() and showNormal() have issues changing the state. This makes setGeometry troublesome as well.

      https://bugreports.qt.io/browse/QTBUG-16034

      I spend hours searching this forum and others finally finding the bug report.

      So if moderators allow let's have it here for record of others searching for the cause.

      J Offline
      J Offline
      JonB
      wrote on 8 Aug 2023, 14:09 last edited by
      #2

      @Seb-Tur
      That issue refers to "metacity" under GNOME. I don't know that it has general/any applicability nowadays. It also is about whether min/max buttons can be shown on a dialog, whereas you seem to be asking about code.

      FWIW I tried under 22.04 and it seemed to work OK. Default GNOME/Mutter. showMaximized() seem to work from code. I cannot be sure what else you saw for "troublesome".

      S 1 Reply Last reply 18 Aug 2023, 11:18
      0
      • J JonB
        8 Aug 2023, 14:09

        @Seb-Tur
        That issue refers to "metacity" under GNOME. I don't know that it has general/any applicability nowadays. It also is about whether min/max buttons can be shown on a dialog, whereas you seem to be asking about code.

        FWIW I tried under 22.04 and it seemed to work OK. Default GNOME/Mutter. showMaximized() seem to work from code. I cannot be sure what else you saw for "troublesome".

        S Offline
        S Offline
        Seb Tur
        wrote on 18 Aug 2023, 11:18 last edited by Seb Tur
        #3

        @JonB

        tested again on mine,

           QDialog dialog(parent_widget);
           dialog.setObjectName("messageDialog");
           dialog.setWindowIcon(icon);
           dialog.setWindowTitle(title);
           dialog.setWindowFlags(Qt::Window);
           dialog.showMaximized();
           bool res = dialog.exec()
        

        if I skip setWindowFlags(Qt::Window) then dialog is not maximized at all

        J 1 Reply Last reply 18 Aug 2023, 11:46
        1
        • S Seb Tur
          18 Aug 2023, 11:18

          @JonB

          tested again on mine,

             QDialog dialog(parent_widget);
             dialog.setObjectName("messageDialog");
             dialog.setWindowIcon(icon);
             dialog.setWindowTitle(title);
             dialog.setWindowFlags(Qt::Window);
             dialog.showMaximized();
             bool res = dialog.exec()
          

          if I skip setWindowFlags(Qt::Window) then dialog is not maximized at all

          J Offline
          J Offline
          JonB
          wrote on 18 Aug 2023, 11:46 last edited by
          #4

          @Seb-Tur
          Tested on mine: Ubuntu 22.04, Qt 5.15.3, GNOME. Works fine (maximizes) with or without setWindowFlags(Qt::Window).

          Check you are running under Xorg, not Wayland? Wayland may not allow such stuff?

          1 Reply Last reply
          0
          • S Seb Tur has marked this topic as unsolved on 5 Mar 2025, 07:51
          • S Offline
            S Offline
            Seb Tur
            wrote on 5 Mar 2025, 07:54 last edited by
            #5

            Reopening,
            now I tried to make a windows10 build for my app and show dialog.showMaxmized() does not work, the window is just a fraction of the screen.

            this is how i do it:

                if (touchscreen) {
                    qDebug()<<"Showing maximized, it is touchscreen";
                    setWindowFlags(windowFlags() | Qt::Window);
                    setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
                    showMaximized();
                } else {
                    qDebug()<<"no touchscreen, getting screen geometry and calculate the size to occupy half of the screen";;
                    QRect screenGeometry = QApplication::primaryScreen()->geometry();
                    int width = screenGeometry.width() / 2;
                    int height = screenGeometry.height() / 2;
                    int x = (screenGeometry.width() - width) / 2;
                    int y = (screenGeometry.height() - height) / 2;
            
                    // Set the geometry of the dialog to be centered and occupy half the screen
                    setGeometry(x, y, width, height);
                    show();
                }
            
                exec();
            
            J 1 Reply Last reply 5 Mar 2025, 08:38
            0
            • S Seb Tur
              5 Mar 2025, 07:54

              Reopening,
              now I tried to make a windows10 build for my app and show dialog.showMaxmized() does not work, the window is just a fraction of the screen.

              this is how i do it:

                  if (touchscreen) {
                      qDebug()<<"Showing maximized, it is touchscreen";
                      setWindowFlags(windowFlags() | Qt::Window);
                      setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
                      showMaximized();
                  } else {
                      qDebug()<<"no touchscreen, getting screen geometry and calculate the size to occupy half of the screen";;
                      QRect screenGeometry = QApplication::primaryScreen()->geometry();
                      int width = screenGeometry.width() / 2;
                      int height = screenGeometry.height() / 2;
                      int x = (screenGeometry.width() - width) / 2;
                      int y = (screenGeometry.height() - height) / 2;
              
                      // Set the geometry of the dialog to be centered and occupy half the screen
                      setGeometry(x, y, width, height);
                      show();
                  }
              
                  exec();
              
              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 5 Mar 2025, 08:38 last edited by
              #6

              @Seb-Tur said in QDialog Showmaximized not working:

              Showing maximized, it is touchscreen

              Is this printed if you run your app?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Seb Tur
                wrote on 5 Mar 2025, 09:39 last edited by Seb Tur 9 days ago
                #7

                yes it is printed
                I also do check
                qDebug()<<"isMaximized: "<<isMaximized();
                which returns 1 after showMaximized() even if the window does not get maximized.

                my dirty trick right now is to add

                #ifdef Q_OS_WIN
                        QWidget *parentWidget = static_cast<QWidget *>(parent());
                        if (parentWidget)
                            setGeometry(parentWidget->geometry());
                #endif
                

                just after showMaximized()

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Seb Tur
                  wrote on 5 Mar 2025, 11:01 last edited by
                  #8

                  what is strange that showFullScreen() works ok

                  Pl45m4P 1 Reply Last reply 5 Mar 2025, 11:04
                  0
                  • S Seb Tur
                    5 Mar 2025, 11:01

                    what is strange that showFullScreen() works ok

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on 5 Mar 2025, 11:04 last edited by
                    #9

                    @Seb-Tur said in QDialog Showmaximized not working:

                    what is strange that showFullScreen() works ok

                    Therefore check this topic.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    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