Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135883

Submenus incorrectly bounded to main window on Wayland

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9.0
    • GUI: Menus
    • None
    • Arch Linux with labwc compositor
    • Linux/Wayland

    Description

      On Wayland, when an application's main window is positioned near the bottom of the screen, submenus are incorrectly positioned at-or-below the top of the main window, causing them to be misaligned relative to the parent menu.

      This is due to positioning logic in QMenuPrivate::popup() which tries to position the menu at-or-below the global coordinate (0,0). On other window systems (e.g. X11) this is fine and good, because it keeps the menu on-screen. But on Wayland, the "global" coordinate system is actually not global, it's relative to the main window. Therefore there is nothing special about the coordinate (0,0), and the submenu should be allowed to pop up at negative coordinates.

      A simple fix is to set the "adjustToDesktop" bool in QMenuPrivate::popup() to false when running on Wayland. This disables the logic which limits the submenu position to be at-or-below (0,0).

      bool adjustToDesktop =
          !q->window()->testAttribute(Qt::WA_DontShowOnScreen) &&
          !qApp->nativeInterface<QNativeInterface::QWaylandApplication>();

      Patch: 0001-Fix-submenu-positioning-on-Wayland.patch

      Test case:

      for (int i = 0; i < 10; i++)
      {
          editMenu->addAction(QString("action %1").arg(i));
      } 
      • Build and run the example
      • Move the window to the bottom of the screen
      • Open the Edit -> Format submenu
      • Note that the submenu is not aligned with the Format item in the Edit menu

      Before screenshot:

      After screenshot:

      Attachments

        1. 0001-Fix-submenu-positioning-on-Wayland.patch
          1 kB
          John Lindgren
        2. menu-bugged.png
          225 kB
          John Lindgren
        3. menu-fixed.png
          221 kB
          John Lindgren

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              john.lindgren@aol.com John Lindgren
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes