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

Make text-matching MenuRole guessing optional on OS X

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 4.8.6, 4.8.7, 5.3.1, 5.4.0 RC
    • None
    • OS X, and especially KDE on OS X.

    • macOS

    Description

      OS X has a so-called Application menu, which hosts the About, Preferences and Quit menu items, normally attached to other menus on other OSes.

      Qt creates QAction objects with a TextHeuristic MenuRole by default, and then uses QAction::text pattern matching against relevant strings to determine whether an action being added to a menu has to appear in that menu, or in the Application menu.
      This is a convenience feature supposed to make applications look more Mac-like even if the author doesn't use setMenuRole to indicate what QAction should go under Preferences, etc.

      As all artificial intelligence, this heuristic is brittle. Unexpected patterns can match (esp. with translated applications, or applications that only exist in non-English languages) and there is no way to override a mis-attribution.

      As an example consider KDevelop, KDE's IDE which is of course built on Qt. It will create a menu action called "Configure selection" which does not open a configuration dialog or preferences panel, but instead launches the selected project's configure procedure.

      This action fits the matching criteria, and because it is the first one to do so, it is installed under Preferences. The real preferences action, called "Configure KDevelop..." is created much later (the last one matching the heuristic in fact). And even if it is explicitly setMenuRole(PreferencesRole), the Preferences menu item is already taken.

      The result is that

      • the user is likely to and will trigger projects' configure step unwittingly
      • users looking to launch the configure step won't find the command because it has been given an unexpected and irrelevant name and location.

      Other KDE applications have been shown to have the wrong About action, and trigger unexpected other settings panels through the Preferences menu item. The Kontact application for instance reorganises its Settings menu each time one changes the selected plugin (it's a wrapper for applications that can also run standalone). Is it really possible for a generic pattern-matching algorithm to intervene in that process and guarantee an outcome with the right action attached to Apple's Preferences menu item, without guidance from the application?

      Pure Qt applications seem less affected, presumably because they do not simply rely on the heuristic , but use setMenuRole() explicitly (and at the appropriate time).

      I have been testing a Qt 4.8.6 patch that deactivates the heuristic for About and Preferences. This has little effect on pure Qt applications, but KDE applications no longer suffer from misplaced menu actions that can even invoke unexpected and irrelevant actions.
      I think that is more important than Mac-like looks (function over form anytime), and of course it is little trouble to use the proper setMenuRole() (KDE already has a provision for such "standard actions".
      NB: using setMenuRole(PreferencesRole) on an action only has the expected effect if no action has been given that role yet, which is a source of unexpected surprise for programmers...

      I would thus suggest a global switch either to make QActions be NoRole at creation or to (selectively) prevent overly broad text-matching heuristics to guesstimate menu action placement. For the Quit role (and Cut, Copy, Paste and SelectAll roles in Qt5), full-string comparison is used, which makes the margin for misunderstanding much smaller.

      BTW: is there really a need for those Cut, Copy Paste etc. heuristics in Qt5? Quick tests with those heuristics deactivated seem to suggest that they aren't required.

      Attachments

        Issue Links

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

          Activity

            People

              sorvig Morten Sørvig
              rjvbertin René Bertin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes