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. Why does QRect isValid return false?

Why does QRect isValid return false?

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

    I have the following:

    QRect rctSection;
    rctSection.setWidth(mszOffscreen.width());
    rctSection.setTop((intViewMax - 1) * mptPixelsPerBSCAN.y());
    rctSection.setBottom((intViewMin - 1) * mptPixelsPerBSCAN.y());
    

    Line 1, rctSection created and contains all 0's.
    Line 2, width is set to 72
    Line 3, top is set to 3998
    Line 4, bottom is set to 0

    After this I use isValid to test geometry:

    if ( rctSection.isValid() == true ) {
    

    It doesn't get into the scope of the condition indicating that isValid has returned false. Why? In the debugger, rctSection shows:

    x1:   0
    y1:  3998
    x2: 71
    y2: -1
    

    Why does y2 contain 1 ?

    I need to set the bottom and top and not setHeight, is Bottom expected to be greater than Top ?

    [Edit] It appears this is the problem, having switch around the contents of setTop and setBottom it works.

    Kind Regards,
    Sy

    SPlattenS 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I have the following:

      QRect rctSection;
      rctSection.setWidth(mszOffscreen.width());
      rctSection.setTop((intViewMax - 1) * mptPixelsPerBSCAN.y());
      rctSection.setBottom((intViewMin - 1) * mptPixelsPerBSCAN.y());
      

      Line 1, rctSection created and contains all 0's.
      Line 2, width is set to 72
      Line 3, top is set to 3998
      Line 4, bottom is set to 0

      After this I use isValid to test geometry:

      if ( rctSection.isValid() == true ) {
      

      It doesn't get into the scope of the condition indicating that isValid has returned false. Why? In the debugger, rctSection shows:

      x1:   0
      y1:  3998
      x2: 71
      y2: -1
      

      Why does y2 contain 1 ?

      I need to set the bottom and top and not setHeight, is Bottom expected to be greater than Top ?

      [Edit] It appears this is the problem, having switch around the contents of setTop and setBottom it works.

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

      @SPlatten , for some reason bottom cannot be greater than top, switch around values and now its valid.

      Kind Regards,
      Sy

      KroMignonK 1 Reply Last reply
      0
      • SPlattenS SPlatten

        @SPlatten , for some reason bottom cannot be greater than top, switch around values and now its valid.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #3

        @SPlatten said in Why does QRect isValid return false?:

        for some reason bottom cannot be greater than top, switch around values and now its valid.

        This is because it is the wanted behavior(cf documentation)

        A valid rectangle has a left() <= right() and top() <= bottom(). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        SPlattenS 1 Reply Last reply
        3
        • KroMignonK KroMignon

          @SPlatten said in Why does QRect isValid return false?:

          for some reason bottom cannot be greater than top, switch around values and now its valid.

          This is because it is the wanted behavior(cf documentation)

          A valid rectangle has a left() <= right() and top() <= bottom(). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).

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

          @KroMignon , its that strange tho, because the default coordinate system starts at 0,0 top left, the term top implies it is higher than bottom, which obviously isn't the case.

          Kind Regards,
          Sy

          KroMignonK 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @KroMignon , its that strange tho, because the default coordinate system starts at 0,0 top left, the term top implies it is higher than bottom, which obviously isn't the case.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @SPlatten said in Why does QRect isValid return false?:

            its that strange tho, because the default coordinate system starts at 0,0 top left, the term top implies it is higher than bottom, which obviously isn't the case.

            No, that is totally conform to Qt coodinates system:
            ca876b64-656a-47cd-8de4-b1d2ce362024-image.png

            Top is lower than Botton and Left is lower than Right

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            7

            • Login

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