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

Modifying a font in style delegate doesn't work when text is elided

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.12.2, 5.14.0 Alpha
    • 4.8.5, 5.1.1
    • Widgets: Itemviews
    • None
    • Windows, Linux
    • 25133a1b77c059e32760f3d288c985183d86da4a (qt/qtbase/5.12)

      Only happens if the item's font is overridden (even by its own copy like in the following example).

      #include <QApplication>
      #include <QStandardItemModel>
      #include <QStyledItemDelegate>
      #include <QTreeView>
      
      class Delegate : public QStyledItemDelegate
      {
      public:
          void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
          {
              QStyleOptionViewItem o = option;
              o.font.setBold(true);
              QStyledItemDelegate::paint(painter, o, index);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QStandardItemModel model;
          Delegate delegate;
          QStandardItem item("Quite a long string for testing font overriding");
          item.setFont(item.font());
          model.setItem(0, 0, &item);
          QTreeView view;
          view.setItemDelegate(&delegate);
          view.setModel(&model);
          view.show();
          return app.exec();
      }

        1. elided.png
          5 kB
          Orgad Shaneh
        2. expanded.png
          5 kB
          Orgad Shaneh
        3. main.cpp
          1 kB
          Christian Ehrlicher
        For Gerrit Dashboard: QTBUG-34133
        # Subject Branch Project Status CR V

            chehrlic Christian Ehrlicher
            orgads Orgad Shaneh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes