MathEditDelegate
::MathEditDelegate(QObject *parent
) : QStyledItemDelegate(parent)
{
}
if(MathEdit* edit = qobject_cast<MathEdit*>(editor)){
QString currentText
= index.
data(Qt
::DisplayRole | Qt
::EditRole).
toString();
edit->setHtml(currentText);
}
else
QStyledItemDelegate::setEditorData(editor, index);
}
bool MathEditDelegate
::eventFilter(QObject *editor,
QEvent *event
){ if(event
->type
()==QEvent::KeyPress){ qDebug()<<editor->metaObject()->className(); //This should be MathEdit, but instead is always QExpandingLineEdit
return false;
}
return QStyledItemDelegate::eventFilter(editor, event);
}
if(MathEdit* edit = qobject_cast<MathEdit*>(editor)){
model->setData(index, edit->toHtml(), Qt::DisplayRole | Qt::EditRole);
}
else
QStyledItemDelegate::setModelData(editor, model, index);
}
MathEdit* edit = new MathEdit(parent);
return edit;
}
MathEditDelegate::MathEditDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
void MathEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{
if(MathEdit* edit = qobject_cast<MathEdit*>(editor)){
QString currentText = index.data(Qt::DisplayRole | Qt::EditRole).toString();
edit->setHtml(currentText);
}
else
QStyledItemDelegate::setEditorData(editor, index);
}
bool MathEditDelegate::eventFilter(QObject *editor, QEvent *event){
if(event->type()==QEvent::KeyPress){
qDebug()<<editor->metaObject()->className(); //This should be MathEdit, but instead is always QExpandingLineEdit
return false;
}
return QStyledItemDelegate::eventFilter(editor, event);
}
void MathEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
if(MathEdit* edit = qobject_cast<MathEdit*>(editor)){
model->setData(index, edit->toHtml(), Qt::DisplayRole | Qt::EditRole);
}
else
QStyledItemDelegate::setModelData(editor, model, index);
}
QWidget* MathEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/){
MathEdit* edit = new MathEdit(parent);
return edit;
}
To copy to clipboard, switch view to plain text mode
I've implemented createEditor so shouldn't the editor in eventFilter be the editor I created and not the default "QExpandingLineEdit"?
Bookmarks