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. QMessageBox position and size are wrong

QMessageBox position and size are wrong

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 983 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.
  • C Christian Ehrlicher
    16 Jun 2024, 16:47

    Do you use wayland?

    K Offline
    K Offline
    kepeter
    wrote on 16 Jun 2024, 16:58 last edited by kepeter
    #3

    @Christian-Ehrlicher
    Yes

    And I mean by that, that Fedora 39 using wayland...

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JonB
      wrote on 16 Jun 2024, 20:28 last edited by
      #4

      There are many threads about Wayland controlling window positions instead of your program.

      K 1 Reply Last reply 17 Jun 2024, 14:53
      0
      • J JonB
        16 Jun 2024, 20:28

        There are many threads about Wayland controlling window positions instead of your program.

        K Offline
        K Offline
        kepeter
        wrote on 17 Jun 2024, 14:53 last edited by
        #5

        @JonB
        I do not understand what are you suggesting... I do not control not size neither position. I left it to the default, which - to my understanding - should be centred...
        And if I have to write special code to deal with the underlying wayland layer, then what the point in QT?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JonB
          wrote on 17 Jun 2024, 16:18 last edited by JonB
          #6

          I am not suggesting anything.

          I was expecting - and remember that it was so - the message box to be centred on its parent and be correctly sized... But I got this...

          I asked whether you are running under Wayland. If so, Wayland will position the message box for you, and that may override the centering of a message box which perhaps used to happen under, say, Xorg, if that is what you used in the past.

          And if I have to write special code to deal with the underlying wayland layer, then what the point in QT?

          You don't have to write special code if it is a Wayland issue, and indeed it would be difficult to do so. Rather you accept that Wayland positions windows according to its rules. (Part of) The point of Qt is to provide a platform-independent layer for code including windowing functionality, not to somehow override or by-pass the native windowing system/manager.

          The first thing is to ascenrtain if you are running under Wayland. If you are not this is not relevant. If you are then try your code under Xorg and see if different behaviour?

          See also perhaps
          https://forum.qt.io/topic/157268/pyside6-the-move-method-cannot-move-the-specified-parameter-under-the-ubuntu22-04-system-how-should-this-problem-be-solved-so-that-it-can-be-centered-horizontally-and-vertically

          K 1 Reply Last reply 17 Jun 2024, 17:08
          0
          • J JonB
            17 Jun 2024, 16:18

            I am not suggesting anything.

            I was expecting - and remember that it was so - the message box to be centred on its parent and be correctly sized... But I got this...

            I asked whether you are running under Wayland. If so, Wayland will position the message box for you, and that may override the centering of a message box which perhaps used to happen under, say, Xorg, if that is what you used in the past.

            And if I have to write special code to deal with the underlying wayland layer, then what the point in QT?

            You don't have to write special code if it is a Wayland issue, and indeed it would be difficult to do so. Rather you accept that Wayland positions windows according to its rules. (Part of) The point of Qt is to provide a platform-independent layer for code including windowing functionality, not to somehow override or by-pass the native windowing system/manager.

            The first thing is to ascenrtain if you are running under Wayland. If you are not this is not relevant. If you are then try your code under Xorg and see if different behaviour?

            See also perhaps
            https://forum.qt.io/topic/157268/pyside6-the-move-method-cannot-move-the-specified-parameter-under-the-ubuntu22-04-system-how-should-this-problem-be-solved-so-that-it-can-be-centered-horizontally-and-vertically

            K Offline
            K Offline
            kepeter
            wrote on 17 Jun 2024, 17:08 last edited by
            #7

            @JonB

            Thank you for the explanation - now I see what you was saying...
            I was under the impression - based on what I saw in the documentation - that the modal shuld be automatically centred by QT, regardless of the underlying technology...
            Displays a simple message box about Qt, with the given title and centered over parent (if parent is not nullptr).
            Not aboutQt neither question does it...

            I will try what called 'property-based API' in the documentation to solve the problem...

            Thank you

            J 1 Reply Last reply 17 Jun 2024, 17:30
            0
            • K kepeter
              17 Jun 2024, 17:08

              @JonB

              Thank you for the explanation - now I see what you was saying...
              I was under the impression - based on what I saw in the documentation - that the modal shuld be automatically centred by QT, regardless of the underlying technology...
              Displays a simple message box about Qt, with the given title and centered over parent (if parent is not nullptr).
              Not aboutQt neither question does it...

              I will try what called 'property-based API' in the documentation to solve the problem...

              Thank you

              J Offline
              J Offline
              JonB
              wrote on 17 Jun 2024, 17:30 last edited by
              #8

              @kepeter
              I agree about that doc quote, but I am not sure whether it does not apply under Wayland. You still have not stated whether you are running under Wayland. If you are, and that is the reason, there is nothing for you to do about it. I don't know about a "property-based API'". Leave it to you to find out if you are under Wayland and this is a Wayland behaviour.

              K 1 Reply Last reply 17 Jun 2024, 18:00
              0
              • J JonB
                17 Jun 2024, 17:30

                @kepeter
                I agree about that doc quote, but I am not sure whether it does not apply under Wayland. You still have not stated whether you are running under Wayland. If you are, and that is the reason, there is nothing for you to do about it. I don't know about a "property-based API'". Leave it to you to find out if you are under Wayland and this is a Wayland behaviour.

                K Offline
                K Offline
                kepeter
                wrote on 17 Jun 2024, 18:00 last edited by
                #9

                @JonB

                I missed your question about wayland (answered it earlier) - Fedora 39 uses wayland so I'm using it...

                I fiddled with the message box and found this:

                msg1 will center on the parent window, but will not show title bar

                    QMessageBox msg1;
                
                    msg1.setParent(this);
                    msg1.setText("Are you sure?");
                    msg1.setWindowTitle("Exit");
                    msg1.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
                    msg1.setDefaultButton(QMessageBox::No);
                    msg1.setIcon(QMessageBox::Question);
                    msg1.setWindowFlags(Qt::Popup);
                
                    msg1.exec();
                

                9a85871c-c6a3-47f5-bcd1-c96612bc18bd-image.png

                msg2 will show title bar, but will not center

                    QMessageBox msg2;
                
                    msg2.setParent(this);
                    msg2.setText("Are you sure?");
                    msg2.setWindowTitle("Exit");
                    msg2.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
                    msg2.setDefaultButton(QMessageBox::No);
                    msg2.setIcon(QMessageBox::Question);
                    msg2.setWindowFlags(Qt::Dialog);
                
                    msg2.exec();
                

                9810e3cc-c311-49e3-9aa1-de9703c340eb-image.png

                It seems some sort of bug - not sure where exactly, however I can be with the first option... So I will call it a day...

                Thank you...

                1 Reply Last reply
                0
                • K kepeter
                  16 Jun 2024, 16:44

                  I had this application on hold for a long time and when came back - on new OS install with latest QT 6 - I encountered a problem with QMessageBox...

                  void AppWindow::closeEvent(QCloseEvent *event)
                  {
                      if(QMessageBox::question(this, "Exit", "Are you sure?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
                      {
                          computer.requestInterruption();
                          computer.wait();
                  
                          event->accept();
                      }
                      else
                      {
                          event->ignore();
                      }
                  }
                  

                  I was expecting - and remember that it was so - the message box to be centred on its parent and be correctly sized... But I got this...
                  f42cce59-85c2-4f7c-8e22-c9a9ca66095d-image.png

                  As you can see the message box not centred and the size is incorrect, as the title not even shows...

                  This is my environment:
                  OS: Fedora 39
                  QT: 6.6.2
                  QT Creator: 10.0.2
                  Compiler: gcc 13.3.1

                  While everything functioning perfectly I would like it to be also pleasing to the eye...

                  A Offline
                  A Offline
                  anil_arise
                  wrote on 19 Jun 2024, 10:45 last edited by
                  #10

                  @kepeter

                  You can use move as per designated co-ordinates

                  Example:
                  msg1.move(this->width()/2,this->height()/2)

                  C 1 Reply Last reply 19 Jun 2024, 10:58
                  0
                  • A anil_arise
                    19 Jun 2024, 10:45

                    @kepeter

                    You can use move as per designated co-ordinates

                    Example:
                    msg1.move(this->width()/2,this->height()/2)

                    C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 19 Jun 2024, 10:58 last edited by
                    #11

                    @anil_arise Wayland does not allow moving top level widgets. Otherwise the OP would not have such problems...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    K 1 Reply Last reply 19 Jun 2024, 12:18
                    1
                    • C Christian Ehrlicher
                      19 Jun 2024, 10:58

                      @anil_arise Wayland does not allow moving top level widgets. Otherwise the OP would not have such problems...

                      K Offline
                      K Offline
                      kepeter
                      wrote on 19 Jun 2024, 12:18 last edited by
                      #12

                      @Christian-Ehrlicher
                      These are NOT top-level... Every and each has a parent...

                      J 1 Reply Last reply 19 Jun 2024, 13:14
                      0
                      • K kepeter
                        19 Jun 2024, 12:18

                        @Christian-Ehrlicher
                        These are NOT top-level... Every and each has a parent...

                        J Offline
                        J Offline
                        JonB
                        wrote on 19 Jun 2024, 13:14 last edited by
                        #13

                        @kepeter said in QMessageBox position and size are wrong:

                        These are NOT top-level... Every and each has a parent...

                        It is top-level. Read https://doc.qt.io/qt-6/qdialog.html#QDialog

                        Constructs a dialog with parent parent.

                        A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent

                        Dialogs only use parent for positioning. And we believe Wayland ignores/does not allow that.

                        K 1 Reply Last reply 19 Jun 2024, 16:26
                        1
                        • J JonB
                          19 Jun 2024, 13:14

                          @kepeter said in QMessageBox position and size are wrong:

                          These are NOT top-level... Every and each has a parent...

                          It is top-level. Read https://doc.qt.io/qt-6/qdialog.html#QDialog

                          Constructs a dialog with parent parent.

                          A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent

                          Dialogs only use parent for positioning. And we believe Wayland ignores/does not allow that.

                          K Offline
                          K Offline
                          kepeter
                          wrote on 19 Jun 2024, 16:26 last edited by
                          #14

                          @JonB

                          It sounds me like an implementation issue of Qt against wayland... It is clear that there is no problem to center a child dialog - every gnome application does it...

                          Thank you

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 19 Jun 2024, 16:30 last edited by Christian Ehrlicher
                            #15

                            It's not a child dialog but a top level widget. Child dialogs are properly centered as you can see in the testcase above.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            0

                            12/15

                            19 Jun 2024, 12:18

                            • Login

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