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. normalGeometry seems offset

normalGeometry seems offset

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 558 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.
  • D Offline
    D Offline
    dcaputi
    wrote on last edited by dcaputi
    #1

    The following snippet of code results in 'this' top-level widget moving/shifting on screen:
    auto pt = this->normalGeometry().topLeft();
    this->move(pt);

    This is creating a problem because I'm using normalGeometry to persist the position and size of the window on app exit without regards to it being minimized/maximized.
    This seems like a bug because the geometry returned has the correct dimensions ... so what am I missing?

    BTW, I'm using QT 5.9 on Windows 10.

    EDIT:
    The work-around is to adjust the normalized position by the client area offset:
    pt.ry() -= geometry().top() - y();
    pt.rx() -= geometry().left() - x();

    As I mentioned above, the width and height is OK and does not need to be adjusted.
    My opinion is that normalGeometry should adjust the position internally to be consistent with the size being that of the outer frame.

    Dan C.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Shouldn't you be using the frameGeometry in order to move your widget since it's a top level window ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Shouldn't you be using the frameGeometry in order to move your widget since it's a top level window ?

        D Offline
        D Offline
        dcaputi
        wrote on last edited by
        #3

        @SGaist - that snippet of code was an attempt to simplify the issue. Here's the bigger picture in pseudo-code:

        void MyAppWidget::closeEvent()
        {
            // save "restored" window geometry if it's maximized or minimized 
            QSize sz = normalGeometry().size();
            QPoint pt = normalGeometry().topLeft();
            SaveSettings(sz, pt);
        }
        
        MyAppWidget::MyAppWidget()
        {
            QSize sz; QPoint pt;
            LoadSettings(sz, pt);
            resize(sz);  // this is ok (width and height included the frame)
            move(pt);    // this is not (top-left did NOT include the frame)
        }
        

        The main idea is that the app should not fill the entire screen or resize to an icon sized window when it's launched. However, the code above puts the window in a noticeably offset position. I do have a work-around - I just think this is a bug or a bad inconsistency at best.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have the same behaviour with a more recent version of Qt ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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