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

[4->5->6 REG?] Support for Qt::TextFlags as Qt::TextAlignmentRole

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.0
    • None

    Description

      qttools/src/shared/qttoolbardialog/qttoolbardialog.cpp:1068 (Qt Designer/Toolbar editor solution) does this:

                  item = new QListWidgetItem(action->text());
                  item->setIcon(action->icon());
                  item->setTextAlignment(Qt::Alignment(Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic));
      

      setTextAlignment used to take a plain int, allowing such a mix-n-match of item flags. After 53ee4c8b1f7ae72e7005166e1c0dbc4659f2ab32 https://codereview.qt-project.org/c/qt/qtbase/+/401695 , the explicit cast became necessary.

      Still: in Qt 5 and Qt 6, the mnemonic is NOT drawn. It used to be, at some point in Qt 4:

      https://docs.huihoo.com/qt/solutions/4/qttoolbardialog/qttoolbardialog.html

      This opens up a lot of questions: mainly, is this a regression? If so, how to restore support for it?

      Some general considerations:

      • Qt::Alignment and Qt::TextFlag are meant to be combined (their enumerators don't overlap). There is a number of APIs that take a plain int for such a combination (e.g. QPainter::drawText, QFontMetrics::boundingRect). Yes, int is a type-unsafe API, see QTBUG-99948 for a discussion about that
      • Qt::TextAlignmentRole is also passed around as plain int. The documentation says that it should be a Qt::Alignment, but it's a lie (QTBUG-75172, QTBUG-74639). In terms of public APIs, the situation in item widget classes was inconsistent, with things like QStandardItem actually taking a Qt::Alignment (but storing an int!), and things like QXXXWidgetItem taking the int directly.
      • Item delegates extract an int from the model, cast it as Qt::Alignment, and set it on the style option that is then used to draw one specific model index. Given Qt::Alignment is wide enough, in principle this still allows any extra text flags to reach the style and be honored there.
      • ... but this doesn't seem to happen. In particular, the alignment from the style option is set on a QTextOption which is used to draw the text, and QTextOption stores the alignment in a 8-bit bitfield, therefore losing the textflags (Qt::Alignment is indeed 8 bits, Qt::TextFlag uses upper bits).

      Attachments

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              peppe Giuseppe D'Angelo
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: