[NOT SOLVED] Unable to set font of the widget derived from QPlainTextEdit
-
bq. With the code, the font was changed and qDebug output is right. So you problem is the display text’s font doesn’t change?
yes!
-
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. :-)
-
AFAIK this way I can't obtain current font. I would like to save which font is used and load it again from setting file.
-
So doesn't anybody know what's happening here?
Should I give more details or codes ? -
I'm still waiting....
-
@document()->setDefaultFont(myFont);@
The problem is that you set the font on the widget, but not the content. -
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. -
In that case I'll need to see the code where you insert the text into your widget. If you do it by hand, then it should be in the default font.
-
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;
@ -
I have a guess... I used Qt4SyntaxHighlighter that reads a css file and applies highlighting on the content. I didn't set any font in that css file (just colors). Is this related to syntax highlighter ?