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. How to fix inconsistent window placement?
Forum Updated to NodeBB v4.3 + New Features

How to fix inconsistent window placement?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 180 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.
  • D Offline
    D Offline
    DerReisende
    wrote on last edited by
    #1

    Hello everybody!

    I am using Qt 6.8b2 (same happens with Qt 6.7.2 as well) both on Windows 11 and macOS Sonoma 14.5 and I am currently unable to fix a - for me - annoying inconsistency when trying to place a QTextEdit() in the lower left corner of a single screen:

    m_logWindow = new QTextEdit();
    m_logWindow->setWindowTitle("Log Output");
    m_logWindow->setReadOnly(true);
    m_logWindow->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
    m_logWindow->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint );
    const auto size = m_logWindow->screen()->availableSize();
    m_logWindow->resize(static_cast<int>(std::round(size.width() * 0.75)), 240);
    m_logWindow->show();
    m_logWindow->move(0, size.height() - m_logWindow->frameGeometry().height());
    

    On Windows 11 the result is as expected:
    win_screen.png

    On macOS, the same code however produces a "large" gap between the window and the macOS dock (red rectangle):
    mac_screen.png

    How could I achieve consistent window placement?

    M 1 Reply Last reply
    0
    • D Offline
      D Offline
      DerReisende
      wrote on last edited by
      #3

      @mpergand using size() would discard the height of the bottom dock and place the window behind it.
      However I found the solution to correctly calculate the position by using availableVirtualGeometry(). The returned QRect does take into account the top menu bar height and the calculation basically is now as follows:

      const auto geom = logWindow->screen()->availableVirtualGeometry();
      //qDebug() << "avail virtual geo: " << logWindow->screen()->availableVirtualGeometry();
      logWindow->resize(static_cast<int>(std::round(geom.width() * 0.75)), 240);
      logWindow->show();
      logWindow->move(0, geom.height() + geom.y() - logWindow->frameGeometry().height());
      

      This does work on both platforms.

      1 Reply Last reply
      0
      • D DerReisende

        Hello everybody!

        I am using Qt 6.8b2 (same happens with Qt 6.7.2 as well) both on Windows 11 and macOS Sonoma 14.5 and I am currently unable to fix a - for me - annoying inconsistency when trying to place a QTextEdit() in the lower left corner of a single screen:

        m_logWindow = new QTextEdit();
        m_logWindow->setWindowTitle("Log Output");
        m_logWindow->setReadOnly(true);
        m_logWindow->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
        m_logWindow->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint );
        const auto size = m_logWindow->screen()->availableSize();
        m_logWindow->resize(static_cast<int>(std::round(size.width() * 0.75)), 240);
        m_logWindow->show();
        m_logWindow->move(0, size.height() - m_logWindow->frameGeometry().height());
        

        On Windows 11 the result is as expected:
        win_screen.png

        On macOS, the same code however produces a "large" gap between the window and the macOS dock (red rectangle):
        mac_screen.png

        How could I achieve consistent window placement?

        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #2

        Hi @DerReisende

        const auto size = m_logWindow->screen()->availableSize();
        

        I think with availableSize you don't take the top menu in account.
        Use instead:

        m_logWindow->screen()->size();
        
        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerReisende
          wrote on last edited by
          #3

          @mpergand using size() would discard the height of the bottom dock and place the window behind it.
          However I found the solution to correctly calculate the position by using availableVirtualGeometry(). The returned QRect does take into account the top menu bar height and the calculation basically is now as follows:

          const auto geom = logWindow->screen()->availableVirtualGeometry();
          //qDebug() << "avail virtual geo: " << logWindow->screen()->availableVirtualGeometry();
          logWindow->resize(static_cast<int>(std::round(geom.width() * 0.75)), 240);
          logWindow->show();
          logWindow->move(0, geom.height() + geom.y() - logWindow->frameGeometry().height());
          

          This does work on both platforms.

          1 Reply Last reply
          0
          • D DerReisende has marked this topic as solved on

          • Login

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