Font not work

  • Ok so,im making a code editor application
    and i used Source code Pro as the editor's font

    this 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;
        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;
        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;
        rule.pattern = QRegExp("\\W[0-9]\\W");
        rule.format = txt;
        rule.pattern = QRegExp("##[^\n]*");
        rule.format = singleLineCommentFormat;
        rule.pattern = QRegExp("\\$[^\n]*:");
        rule.format = fFormat;
        rule.pattern = QRegExp("\"[^\n]*\"");
        rule.format = quotationFormat;
        rule.pattern = QRegExp("\'[^\n]*\'");
        rule.format = quotationFormat;
    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);

    please help,i dont know why it doesnt work
    tell me if i need to send any code

    Perhaps the font is not found, or perhaps it does not like your proposed 1pt size for it, which looks pretty small, what are you expecting...?

    Meanwhile, I note you are still using QRegExp instead of QRegularExpression, 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... :)

  • Lifetime Qt Champion


    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

  • Lifetime Qt Champion

    @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

Log in to reply