Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widget geometry issue
Qt 6.12 LTS is out! See what's new in the release blog

Widget geometry issue

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k Views 1 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #1

    Hi! I want to save window geometry to the registry. It all works fine but sometimes I get QWindowsWindow::setGeometry: Unable to set geometry error.

    And registry data is @Rect(32775 32798 1334 600)
    x - 32775
    y - 32798

    I think it's out of bounds of my screen. How to get max X and Y of the screen to check values before setting the geometry. Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      Usually this is caused by having the app on a secondary screen. I usually check desktops and make sure if I'm on a system that doesn't have multiple screens I restore my geometry to the main window.

      Something like:

          auto desktop = QApplication::desktop();
          auto screenLocation = desktop->screenNumber(this);
          if (screenLocation == -1)
          {
              qWarning() << "Main window is not on a valid screen, moving to main screen";
              move(20, 20);
          }
      

      If that isn't what the issue is, then to answer your question you can get the screen geometry with:

      const QRect QDesktopWidget::screenGeometry(int screen = -1) const

      And you can get the desktop widget via application like I did above.

      I would figure out why you are having bad data saved for the geometry though.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      4
      • Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by
        #3

        @ambershark

        I have fixed it by setting nativeEvent and checking for message - SIZE_MAXIMIZED. When window is maximized the values are not saved. Thanks.

        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
        • Unsolved