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. setGeometry Unable to set geometry
Forum Updated to NodeBB v4.3 + New Features

setGeometry Unable to set geometry

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 10.2k Views 2 Watching
  • 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.
  • jsulmJ jsulm

    @SPlatten said in setGeometry Unable to set geometry:

    I've reported the geometry which is

    What do you mean by "reported"?
    Do you mean you print it out? If so where?

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #3

    @jsulm , what I meant was displayed in the console.

    Kind Regards,
    Sy

    mrjjM 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @jsulm , what I meant was displayed in the console.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @SPlatten

      Hi
      It might be the old bug
      https://bugreports.qt.io/browse/QTBUG-73258

      I have seen it on Linux with 5.9 even its listed as 5.12

      you can try set minimumsize on it to
      1246x801 if you haven't done already.

      • QRect(0,0 732x480)
        when do you print this out ? The window must be visible at that time
        or the numbers might mean nothing.
      SPlattenS 1 Reply Last reply
      2
      • mrjjM mrjj

        @SPlatten

        Hi
        It might be the old bug
        https://bugreports.qt.io/browse/QTBUG-73258

        I have seen it on Linux with 5.9 even its listed as 5.12

        you can try set minimumsize on it to
        1246x801 if you haven't done already.

        • QRect(0,0 732x480)
          when do you print this out ? The window must be visible at that time
          or the numbers might mean nothing.
        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #5

        @mrjj , thank you, I just tried that, still the same:

        QWindowsWindow::setGeometry: Unable to set geometry 732x480+-2928+446 on QWidgetWindow/'MainWindowWindow'. Resulting geometry:  738x497+-2928+446 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 732x480, maximum size: 16777215x16777215).
        

        Kind Regards,
        Sy

        Cobra91151C 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @mrjj , thank you, I just tried that, still the same:

          QWindowsWindow::setGeometry: Unable to set geometry 732x480+-2928+446 on QWidgetWindow/'MainWindowWindow'. Resulting geometry:  738x497+-2928+446 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 732x480, maximum size: 16777215x16777215).
          
          Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #6

          @SPlatten

          Hello!

          I have the same issue previously. I fixed it by increasing the size of window/dialog. Try to change the width/height of your window.
          For example, set 740x480 or 740x500. Please let me know if this works for you. Happy coding!

          SPlattenS 1 Reply Last reply
          0
          • Cobra91151C Cobra91151

            @SPlatten

            Hello!

            I have the same issue previously. I fixed it by increasing the size of window/dialog. Try to change the width/height of your window.
            For example, set 740x480 or 740x500. Please let me know if this works for you. Happy coding!

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #7

            @Cobra91151 , size isn't a problem :). really it isn't, it does look like a bug as I'm not sure why the message is reporting -2928 for the width?

            Kind Regards,
            Sy

            Cobra91151C 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @Cobra91151 , size isn't a problem :). really it isn't, it does look like a bug as I'm not sure why the message is reporting -2928 for the width?

              Cobra91151C Offline
              Cobra91151C Offline
              Cobra91151
              wrote on last edited by
              #8

              @SPlatten

              I do not think -2928 is the width. It is the rect.x() position. In your case the width is 732, height - 480, x - 2928 and y - 446.

              You can check out the source:

              void QWindowsWindow::setGeometry(const QRect &rectIn)
              {
                  QRect rect = rectIn;
                  // This means it is a call from QWindow::setFramePosition() and
                  // the coordinates include the frame (size is still the contents rectangle).
                  if (QWindowsGeometryHint::positionIncludesFrame(window())) {
                      const QMargins margins = frameMargins();
                      rect.moveTopLeft(rect.topLeft() + QPoint(margins.left(), margins.top()));
                  }
                  if (m_windowState == Qt::WindowMinimized)
                      m_data.geometry = rect; // Otherwise set by handleGeometryChange() triggered by event.
                  if (m_data.hwnd) {
                      // A ResizeEvent with resulting geometry will be sent. If we cannot
                      // achieve that size (for example, window title minimal constraint),
                      // notify and warn.
                      setGeometry_sys(rect);
                      if (m_data.geometry != rect && (isVisible() || QLibraryInfo::isDebugBuild())) {
                          qWarning("%s: Unable to set geometry %dx%d+%d+%d on %s/'%s'."
                                   " Resulting geometry:  %dx%d+%d+%d "
                                   "(frame: %d, %d, %d, %d, custom margin: %d, %d, %d, %d"
                                   ", minimum size: %dx%d, maximum size: %dx%d).",
                                   __FUNCTION__,
                                   rect.width(), rect.height(), rect.x(), rect.y(),
                                   window()->metaObject()->className(), qPrintable(window()->objectName()),
                                   m_data.geometry.width(), m_data.geometry.height(),
                                   m_data.geometry.x(), m_data.geometry.y(),
                                   m_data.frame.left(), m_data.frame.top(),
                                   m_data.frame.right(), m_data.frame.bottom(),
                                   m_data.customMargins.left(), m_data.customMargins.top(),
                                   m_data.customMargins.right(), m_data.customMargins.bottom(),
                                   window()->minimumWidth(), window()->minimumHeight(),
                                   window()->maximumWidth(), window()->maximumHeight());
                      }
                  } else {
                      QPlatformWindow::setGeometry(rect);
                  }
              }
              

              So, I think the widget geometry is smaller than the layout contents, that is why it reports such issue. You can try to adjustSize method (https://doc.qt.io/archives/qt-5.9/qwidget.html#adjustSize) or you can set it manually.

              Code:

              mpMainWnd->adjustSize();
              mpMainWnd->show();
              

              For example in your case it reports as 738x497 to fix this issue or make it bigger as I suggested in my previous post.

              1 Reply Last reply
              1
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #9

                @Cobra91151 , I've now changed the minimum width and height to 1200x800, still getting:

                QWindowsWindow::setGeometry: Unable to set geometry 1200x800+-3162+286 on QWidgetWindow/'MainWindowWindow'. Resulting geometry:  1206x817+-3162+286 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 1200x800, maximum size: 16777215x16777215).
                

                I took a screen shot of the window and pasted into Paint, the size of the final window is 1208x849.

                Kind Regards,
                Sy

                Cobra91151C 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @Cobra91151 , I've now changed the minimum width and height to 1200x800, still getting:

                  QWindowsWindow::setGeometry: Unable to set geometry 1200x800+-3162+286 on QWidgetWindow/'MainWindowWindow'. Resulting geometry:  1206x817+-3162+286 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 1200x800, maximum size: 16777215x16777215).
                  

                  I took a screen shot of the window and pasted into Paint, the size of the final window is 1208x849.

                  Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on last edited by
                  #10

                  @SPlatten

                  Ok. It would be better to create some minimal test project to reproduce this issue, so I can find a solution.
                  The reason could be a missing parent, widgets size/layouts issue etc.

                  SPlattenS 1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #11

                    @Cobra91151 , thank you, but sorry, that would take more time than I have right now.

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • Cobra91151C Cobra91151

                      @SPlatten

                      Ok. It would be better to create some minimal test project to reproduce this issue, so I can find a solution.
                      The reason could be a missing parent, widgets size/layouts issue etc.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #12

                      @Cobra91151 If the MainWindow is the at the top level of the application, there isn't a parent is there?

                      Kind Regards,
                      Sy

                      Cobra91151C 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @Cobra91151 If the MainWindow is the at the top level of the application, there isn't a parent is there?

                        Cobra91151C Offline
                        Cobra91151C Offline
                        Cobra91151
                        wrote on last edited by
                        #13

                        @SPlatten said in setGeometry Unable to set geometry:

                        @Cobra91151 If the MainWindow is the at the top level of the application, there isn't a parent is there?

                        If you mean something like this:

                        Code:

                        int main(int argc, char *argv[])
                        {
                            QApplication a(argc, argv);
                            Dialog w;
                            w.show();
                            return a.exec();
                        }
                        

                        Then no parent is needed. But, if you have some object class in which you check what dialog to display as the top level, then I would suggest setParent to the app object:

                        Code:

                        int main(int argc, char *argv[])
                        {
                            QApplication a(argc, argv);
                            MyStartup obj;
                            obj.setParent(&a);
                            return a.exec();
                        }
                        

                        But I do not think it will fix your issue. Have you tried for example: setFixedSize method to check if this issue still exists? Also, you can set setWindowFlags method: Qt::MSWindowsFixedSizeDialogHint to make window not resizable on Windows just for a test.

                        Additionally, you can try to find what causes it using the code below in your main method (main.cpp):

                        #ifdef QT_DEBUG
                            qputenv("QT_FATAL_WARNINGS", "1");
                            qputenv("QT_MESSAGE_PATTERN",
                                    "Type: %{type}\nProduct Name: %{appname}\nFile: %{file}\nLine: %{line}\nMethod: %{function}\nThreadID: %{threadid}\nThreadPtr: %{qthreadptr}\nMessage: %{message}");
                         #endif
                        

                        It will work only in Debug mode and should display more details about your issue. Without any code it is hard to find the root of your issue.

                        1 Reply Last reply
                        1

                        • Login

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