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

QAction::setText() and QAction::setSeparator() call order effect

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P5: Not important
    • None
    • 5.8.0
    • None
    • Mac OS X 10.9.5

    Description

      I am tinkering with a QCocoaMenuItem patch to add support for menu sections, and ran into a side-effect of the order of calling QAction::setSeparator(), QAction::setText() and QMenu::addAction() .

      I'm modifying the menus example as a test application. From that code:

          QAction *action;
      // [a]
          action = formatMenu->addSeparator();
          action->setText(tr("Alignment"));
      //     action->setSeparator(false);
      //     action->setSeparator(true);
      // [b]
          action = new QAction(tr("Alignment2"), this);
          formatMenu->addAction(action);
          action->setSeparator(true);
      // [c]
          action = new QAction(this);
          action->setSeparator(true);
          formatMenu->addAction(action);
          action->setText(tr("Alignment3"));
      

      After 'a' I noticed that my modified QCocoaMenuItem::sync() function draws just a separator, which means that it receives an item with an empty text string. Section 'b' works as intended, and section 'c' just reimplements section 'a' with primitive methods.

      So, turning a texted action into a separator doesn't remove the text, but adding text to a separator doesn't have the expected immediate effect. However, this can be fixed by toggling the separator flag off and back on (commented code in section 'a').

      I think this means that the decision that the Mac style does not implement texted separators is hardwired not only at the level of the drawing routines but also elsewhere. I'd consider that a bug.

      I haven't yet found this location and would appreciate pointers.

      I'm attaching a screenshot of my current native menubar menu section implementation. I think this is already close enough to an acceptable look for a feature that will probably be used only by cross-platform applications (and on which they might rely to make a better self-explaining GUI). This implementation uses only native API calls; specifically it uses [NSMenuItem setAttributedTitle] (already used for alternative font support) to render the section title with cenre alignment, underlining, a slightly heavier stroke and slightly contracted spacing to compensate for the greyed-out rendering of inactive items.

      The 2nd screenshot shows how Fusion renders the same menus when not using a native menubar.

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            rjvbertin René Bertin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes