[Qt-interest] Default font on QTextEdit Delegate
Josh
jnfo-c at grauman.com
Fri Aug 6 21:56:55 CEST 2010
Hello all,
I've been looking up docs and trying to figure this one out for a long
time and I can't figure it out. Any help would be appreciated.
I subclassed QItemDelegate to create a Rich Text delegate based on
QTextEdit/QTextDocument for a QTableWidget. Everything is working fine,
but I am not able to set the "Default Font" for the QTextEdit delegate.
I'm able to set fonts properly, but when in the QTextEdit, if you keep
backspacing and delete everything from the QTextEdit you are able to get
the font to go back to the system font. I've tried calling
QTextDocument::setDefaultFont(), QTextDocument::setDefaultStyleSheet(),
QTextEdit::setFont() and more on the QTextEdit after it is constructed and
this doesn't help. Any thoughts?
Here is the function in my subclass that creates the QTextEdit delegate:
QWidget * HtmlDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
QTextEdit *tableEdit = new QTextEdit(parent);
tableEdit->document()->setDefaultStyleSheet(QString("body, p { style=\"font-family:Arial; font-size:12pt;\" }"));
tableEdit->setStyleSheet(QString("body, p { style=\"font-family:Arial; font-size:12pt;\" }"));
tableEdit->setFont(QFont("Arial",12));
tableEdit->viewport()->setFont(QFont("Arial",12));
tableEdit->setCurrentFont(QFont("Arial",12));
tableEdit->setFontFamily("Arial");
tableEdit->setFontPointSize(12);
tableEdit->document()->setDefaultFont(QFont("Arial",12));
return(tableEdit);
}
Thanks!
Josh
More information about the Qt-interest-old
mailing list