Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Geometry looks invalid but calling isValid returns true.
Qt 6.12 LTS is out! See what's new in the release blog

Geometry looks invalid but calling isValid returns true.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 418 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    In my parent window I pass this to the dialog constructor, I've checked the geometry of the parent window and for some reason it contains:

    x1    -2900
    y1    490
    x2    -2226
    y2    961
    

    I've single stepped into the constructor where I have:

    QRect rctGeom(pParent->geometry());
    rctGeom.setHeight(DataSets::mscuint16Height);
    rctGeom.setWidth(DataSets::mscuint16Width);
    if ( rctGeom.isValid() == true ) {
        setGeometry(rctGeom);
    }
    

    After setting the height and width the geometry contains:

    x1    -2900
    y1    410
    x2    -2445
    y2    949
    

    mscuint16Height contains 540, mscuint16Width contains 456. I've single stepped onto the isValid call and it does return true which I find very odd given that both x1 and x2 are both negative. After calling setGeometry I see in the console:

    QWindowsWindow::setGeometry: Unable to set geometry 480x540+-2900+410 on QWidgetWindow/'DataSetsClassWindow'. Resulting geometry:  486x540+-2900+410 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 480x482, maximum size: 16777215x16777215).
    

    Reading the documentation:
    https://doc.qt.io/qt-5/qrect.html#isValid
    It is certainly doing what it says on the documentation, but personally I think the logic needs and should be changed to validate if the geometry results in a non-visible rectangle as this does.

    This is the logic it currently uses:

    A valid rectangle has a left() <= right() and top() <= bottom().
    

    I think it should be: A valid rectangle should be:

     right() - left() > 0 and top() - bottom() > 0  and
     left() <= right() and top() <= bottom()
    

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I don't see why a rectangle must have postive width or height...

      https://doc.qt.io/qt-5/qrect.html#normalized

      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
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi

        single stepped into the constructor

        You cannot trust size values when in a constructor as Qt will queue certain
        operation until actual shown.

        Try to do the same in showEvent and see.

        1 Reply Last reply
        3

        • Login

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