[Qt-interest] Default font on QTextEdit Delegate
Josh
jnfo-c at grauman.com
Sat Aug 7 00:58:21 CEST 2010
Hello all again,
Once again I finally figured out my problem. I had created a QTextDocument to
create the text which I used to create a QTableWidgetItem, and so that
propagated through all the way to the QTextEdit... Once I set
QTextDocument::setDefaultFont() on the original QTextDocument, then everything
worked. Thanks again for listening :)
Josh
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list