[NOT SOLVED] Unable to set font of the widget derived from QPlainTextEdit
-
Hi
I have a widget derived from QPlainTextEdit. (call it LateXEditor) It have a syntax highlighter, code completer and a line numbering widget on its left side.
The problem is that font of widget is not changed with setFont(). I tried calling setFont in ctor and out of there (after widget is created) but anything not works. The funny thing is that font of sidebar (line numbering area) changes when setFont() for widget is called!
@
// latexedit.h
class LatexTextEdit : public QPlainTextEdit
{
....
}
// latexedit.cpp
LatexTextEdit::LatexTextEdit(QWidget *parent) :
QPlainTextEdit(parent)
{
// ....
setFont(Configuration::instance()->displayFont);
qDebug()<<"F:"<<font(); // output is: F: QFont( "Tahoma,13,-1,5,50,0,0,0,0,0" )
// some other code...
}
@
What I am missing? -
[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;
@