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

QComboMenuDelegate not honoring FontRole and TextColorRole

    XMLWordPrintable

Details

    Description

      It seems the QComboMenuDelegate used in QComboBoxes doesn't respect a lot of the data roles.

      A patch like this makes it work better (there are other roles) that maybe should be respected as well:

      — /tmp/tmp.20535.0 2007-04-02 16:04:26.000000000 -0700
      +++ /home/anders/dev/qt-4.3/src/gui/widgets/qcombobox.cpp 2007-04-02 16:02:44.000000000 -0700
      @@ -67,6 +67,11 @@ QStyleOptionMenuItem QComboMenuDelegate:
      {
      QStyleOptionMenuItem menuOption;
      menuOption.palette = QApplication::palette("QMenu");
      + const QColor col = qVariantValue<QColor>(index.data(Qt::TextColorRole));
      + if (col.isValid())

      { + menuOption.palette.setColor(QPalette::Text, col); + }

      +
      menuOption.state = QStyle::State_None;
      if (mCombo->window()->isActiveWindow())
      menuOption.state = QStyle::State_Active;
      @@ -94,10 +99,14 @@ QStyleOptionMenuItem QComboMenuDelegate:
      extern QHash<QByteArray, QFont> *qt_app_fonts_hash();

      // Make sure fonts set on the combo box also overrides the font for the popup menu.

      • if (mCombo->testAttribute(Qt::WA_SetFont))
        + const QVariant font = index.data(Qt::FontRole);
        + if (!font.isNull()) { + menuOption.font = qVariantValue<QFont>(font); + }

        else if (mCombo->testAttribute(Qt::WA_SetFont))

        { menuOption.font = mCombo->font(); - else + }

        else

        { menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font()); + }

      menuOption.fontMetrics = QFontMetrics(menuOption.font);

      Update: This bug is not yet confirmed; the fix above is straight-forward but gives inconsistent behavior as items in the menu may differ from the current item.

      Attachments

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

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            rve Anders Bakken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes