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

Qt::FontRole is ignored on default delegate editors

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 4.6.3
    • Widgets: Itemviews
    • None
    • Ubuntu 10.04

    Description

      If you have a model (ex. QAbstractTableModel) and provide data for Qt::FontRole, the value is respected when displayed as non-editable string in a view, but not when editing. When editing, it appears to use a default font and not the font reported for that QModelIndex from the model. (I am using a QTableView.)

      For most applications, this is probably just a distraction, making the application look "cheap." For some applications, this is disastrous, because specific fonts are used to render specific columns in different languages, and the default font may not contain glyphs for those languages (Latin, phonetics, Thai, Chinese, etc.)

      I should be able to get-around with a custom delegate, but IMO this behavior should be normal for the default editors. If the application wants to use a certain font to display data, certainly the user should see the same font when editing the data.

      my_model.h
      #ifndef MY_MODEL_H
      #define MY_MODEL_H
      
      #include <QAbstractTableModel>
      #include <QFont>
      
      class MyModel : public QAbstractTableModel {
        Q_OBJECT
      public:
        explicit MyModel(QObject *parent = NULL) : QAbstractTableModel(parent) {}
        int columnCount(const QModelIndex &parent) const {
          return parent.isValid() ? 0 : 2;
        }
        QVariant data(const QModelIndex &, int role) const {
          switch (role) {
          case Qt::DisplayRole:
          case Qt::EditRole:
            return "test";
            break;
          case Qt::FontRole:
            return QFont("Impact", 16);
            break;
          default:
            break;
          }
          return QVariant();
        }
        Qt::ItemFlags flags(const QModelIndex &index) const {
          return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
        }
        QVariant headerData(int, Qt::Orientation, int) const { return "h"; }
        int rowCount(const QModelIndex &parent) const {
          return parent.isValid() ? 0 : 2;
        }
        bool setData(const QModelIndex &, const QVariant &, int) { return false; }
      };
      
      #endif // MY_MODEL_H
      
      main.cpp
      #include <QtGui>
      #include "my_model.h"
      
      int main(int argc, char** argv) {
        QApplication a(argc, argv);
        QTableView view;
        view.setModel(new MyModel(&view));
        view.show();
        return a.exec();
      }
      

      Attachments

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

        Activity

          People

            richard Richard Moe Gustavsen
            dmateer Dave Mateer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes