[NOT SOLVED] Unable to set font of the widget derived from QPlainTextEdit
-
[quote author="Chuck Gao" date="1309615318"]What's the "Configuration::instance()->displayFont" ? Very strange syntax :-)[/quote]
instance() is a static method of Configuration class which returns an instance of Configuration (if not exists crates one and loads font from setting file using QSettings.)
That's not important! I replaced that with this:
@
setFont(QFont("Tahoma"));
@
and nothing happened. -
ok. I forget why this function can not change the font of your plainTextEdit, but there is still a way to make this happend, try style-sheet like this:
@
// this->setFont(QFont("Tahoma"));
this->setStyleSheet(QString("font: bold italic large "Tahoma""));
qDebug() << font(); // The output is not Tahoma, but the displaying text is.
@We can check the document and find what's the differences. :-)
-
Not works!
@
void LatexTextEdit::updateViewSetting()
{
document()->setDefaultFont((Configuration::instance()->displayFont));
this->setFont((Configuration::instance()->displayFont));
qDebug()<<"Widget Font:"<<font();
qDebug()<<"Docement font:"<<document()->defaultFont();
this->update();
}
@
Output is:
@
Widget Font: QFont( "Tahoma,10,-1,5,50,0,0,0,0,0" )
Docement font: QFont( "Tahoma,10,-1,5,50,0,0,0,0,0" )
@
But nothing happens. I tried with new documents too. -
Ok, I call updateViewSetting in my ctor. This is the ctor:
@
LatexTextEdit::LatexTextEdit(QWidget *parent) :
QPlainTextEdit(parent)
{
createWidgets();
createConnections();
// setWordWrapMode(QTextOption::QTextOption::NoWrap);
highlighter = new srchiliteqt::Qt4SyntaxHighlighter(document());
highlighter->init(qApp->applicationDirPath()+"/latex.lang");
highlighter->setFormattingStyle(qApp->applicationDirPath()+"/latex.css");
updateViewSetting();
updateLineNumberAreaWidth();
// highlightCurrentLine();
}
@
and this is definition of class:
@
class LatexTextEdit : public QPlainTextEdit
{
Q_OBJECT
public:
explicit LatexTextEdit(QWidget *parent = 0);
// ....
void updateViewSetting();
// ...
private:
// void highlightCurrentLine();
QStringListModel *model;
QCompleter *completer;
bool completedAndSelected;
srchiliteqt::Qt4SyntaxHighlighter highlighter;
QWidget lineNumberArea;
@