Unsolved Font not work
-
Ok so,im making a code editor application
and i used Source code Pro as the editor's fontthis is stylesheet of plaintext
background-color: #23272a; font: 1pt "Source Code Pro"; color: white; border-style: solid; border-width: 2px; border-color: black; font-size: 30px; padding-left: 2px;
i used syntaxhighlight on it,is its why it doesnt work?
here is full code of highlight cpp:#include "myhighlighter.h" MyHighLighter::MyHighLighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { HighlightingRule rule; keywordFormat.setForeground(QColor("#9477cb")); QStringList keywordPatterns; keywordPatterns << "\\bsay\\b" << "\\bask\\b" << "\\bhyperlink\\b" << "\\breadout\\b" << "\\bsay-previously-read\\b" << "\\b__root__\\b" << "\\b__name__\\b" << "\\b__package__\\b" << "\\b__doc__\\b" << "\\bdelete\\b" << "\\b__keywords__\\b" << "\\bget-html\\b" << "\\bmake\\b" << "\\buse\\b" << "\\b__system_arguments__\\b" << "\\b__change_window_title__\\b" << "\\bstart\\b" << "\\bopen\\b" << "\\bwrite\\b" << "\\bclose\\b" << "\\bwrite-previously-read\\b" << "\\bread\\b" << "\\bget-response\\b" << "\\breturn\\b" << "\\b__get_keywords__\\b" << "\\bread-current\\b" << "\\bset-cursor\\b" << "\\bcompile_atom\\b" << "\\bcompile\\b" << "\\bvar\\b" << "\\b__change_window_title_WE__\\b" << "\\bnothing\\b" << "\\bdelete-directory\\b" << "\\bget\\b" << "\\bnew-window\\b" << "\\bloop\\b" << "\\badd-text\\b" << "\\badd-inputfield\\b" << "\\bconfigure\\b" << "\\badd-space\\b" << "\\berrorize\\b" << "\\blift\\b" << "\\bequation\\b" << "\\bwait\\b" << "\\bexit\\b" << "\\badd-button\\b" << "\\bforget\\b" << "\\bdestroy-window\\b" << "\\bdisable\\b" << "\\benable\\b" << "\\bchange-directory\\b"; foreach (const QString &pattern, keywordPatterns) { rule.pattern = QRegExp(pattern); rule.format = keywordFormat; highlightingRules.append(rule); } ifFormat.setForeground(QColor("#4d4dff")); QStringList ifPatterns; ifPatterns << "\\bif\\b" << "\\bdefault:" << "\\bor\\b" << "\\band\\b" << "\\bTrue\\b" << "\\bFalse\\b" << "\\bNone\\b"; foreach (const QString &pattern, ifPatterns) { rule.pattern = QRegExp(pattern); rule.format = ifFormat; highlightingRules.append(rule); } txt.setForeground(QColor("#00ffae")); rule.pattern = QRegExp("\\W[0-9]\\W"); rule.format = txt; highlightingRules.append(rule); singleLineCommentFormat.setForeground(Qt::darkGray); rule.pattern = QRegExp("##[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); fFormat.setForeground(Qt::yellow); rule.pattern = QRegExp("\\$[^\n]*:"); rule.format = fFormat; highlightingRules.append(rule); quotationFormat.setForeground(QColor("#008f30")); rule.pattern = QRegExp("\"[^\n]*\""); rule.format = quotationFormat; highlightingRules.append(rule); quotationFormat.setForeground(QColor("#008f30")); rule.pattern = QRegExp("\'[^\n]*\'"); rule.format = quotationFormat; highlightingRules.append(rule); } void MyHighLighter::highlightBlock(const QString &text) { foreach (const HighlightingRule &rule, highlightingRules) { QRegExp expression(rule.pattern); int index = expression.indexIn(text); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); } } setCurrentBlockState(0); }
please help,i dont know why it doesnt work
tell me if i need to send any code -
@ELEMENTICY
Perhaps the font is not found, or perhaps it does not like your proposed1pt
size for it, which looks pretty small, what are you expecting...?Meanwhile, I note you are still using
QRegExp
instead ofQRegularExpression
, despite both @SGaist and myself telling you in your other question about regular expressions that you really need to change over. It's nice to know that when we reply you listen to the advice and act on it... :) -
Hi,
There's a full example here.
Use it as a starting point.
Start with only one expression.
Once you have it working, add the other gradually.
If something breaks while adding new patterns, you'll known there's an issue with it. -
@JonB Ikr,thats why i use your as SOLVED
I dont what that mean at that time,and after you replied,i understanded.but now,idk how to use QRegularExpression instead of QRegExp
and i change 1pt to 30px,but its still same -
@ELEMENTICY said in Font not work:
how to use QRegularExpression instead of QRegExp
What is exactly your question? Include QRegularExpression and use it, also read its documentation.
-
@jsulm okay