From c5e97acf497050edffeacf36eeda119e6e1a35b8 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 27 Apr 2024 06:52:18 +0300 Subject: [PATCH] implement font type editing for QItemEditorFactory QTableWidgetItem is still somewhat QString bound because it forces Qt::DisplayRole as Qt::EditRole Signed-off-by: Ivailo Monev --- src/gui/itemviews/qitemdelegate.cpp | 2 +- src/gui/itemviews/qitemeditorfactory.cpp | 34 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index d23f2d64b..7847226c3 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -476,7 +476,7 @@ QWidget *QItemDelegate::createEditor(QWidget *parent, Q_D(const QItemDelegate); if (!index.isValid()) return 0; - QVariant::Type t = static_cast(index.data(Qt::EditRole).userType()); + QVariant::Type t = index.data(Qt::EditRole).type(); const QItemEditorFactory *factory = d->f; if (factory == 0) factory = QItemEditorFactory::defaultFactory(); diff --git a/src/gui/itemviews/qitemeditorfactory.cpp b/src/gui/itemviews/qitemeditorfactory.cpp index 959db9c31..7845e0bd9 100644 --- a/src/gui/itemviews/qitemeditorfactory.cpp +++ b/src/gui/itemviews/qitemeditorfactory.cpp @@ -27,6 +27,7 @@ #include "qcombobox.h" #include "qdatetimeedit.h" +#include "qfontcombobox.h" #include "qlabel.h" #include "qlineedit.h" #include "qspinbox.h" @@ -91,6 +92,7 @@ public: \row \o QPixmap \o QLabel \row \o QString \o QLineEdit \row \o QTime \o QTimeEdit + \row \o QFont \o QFontComboBox \endtable Additional editors can be registered with the registerEditor() function. @@ -181,7 +183,8 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p case QVariant::Bool: { QBooleanComboBox *cb = new QBooleanComboBox(parent); cb->setFrame(false); - return cb; } + return cb; + } #endif #ifndef QT_NO_SPINBOX case QVariant::UInt: { @@ -194,18 +197,22 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p sb->setFrame(false); sb->setMinimum(INT_MIN); sb->setMaximum(INT_MAX); - return sb; } + return sb; + } #endif #ifndef QT_NO_DATETIMEEDIT case QVariant::Date: { QDateTimeEdit *ed = new QDateEdit(parent); - return ed; } + return ed; + } case QVariant::Time: { QDateTimeEdit *ed = new QTimeEdit(parent); - return ed; } + return ed; + } case QVariant::DateTime: { QDateTimeEdit *ed = new QDateTimeEdit(parent); - return ed; } + return ed; + } #endif case QVariant::Pixmap: return new QLabel(parent); @@ -215,7 +222,15 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p sb->setFrame(false); sb->setMinimum(-DBL_MAX); sb->setMaximum(DBL_MAX); - return sb; } + return sb; + } +#endif +#ifndef QT_NO_FONTCOMBOBOX + case QVariant::Font: { + QFontComboBox *fb = new QFontComboBox(parent); + fb->setFrame(false); + return fb; + } #endif #ifndef QT_NO_LINEEDIT case QVariant::String: @@ -225,7 +240,8 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le)); if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le)) le->setWidgetOwnsGeometry(true); - return le; } + return le; + } #else default: break; @@ -254,6 +270,10 @@ QByteArray QDefaultItemEditorFactory::valuePropertyName(QVariant::Type type) con return "time"; case QVariant::DateTime: return "dateTime"; +#endif +#ifndef QT_NO_FONTCOMBOBOX + case QVariant::Font: + return "currentFont"; #endif case QVariant::String: default: