Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Font not work

Font not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++
6 Posts 4 Posters 606 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ELEMENTICY
    wrote on last edited by
    #1

    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;
    
    
    
        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

    JonBJ 1 Reply Last reply
    0
    • E ELEMENTICY

      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;
      
      
      
          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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @ELEMENTICY
      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... :)

      E 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • JonBJ JonB

          @ELEMENTICY
          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... :)

          E Offline
          E Offline
          ELEMENTICY
          wrote on last edited by
          #4

          @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

          jsulmJ 1 Reply Last reply
          0
          • E ELEMENTICY

            @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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            E 1 Reply Last reply
            0
            • jsulmJ jsulm

              @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.

              E Offline
              E Offline
              ELEMENTICY
              wrote on last edited by
              #6

              @jsulm okay

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved