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. [NOT SOLVED] Unable to set font of the widget derived from QPlainTextEdit
Forum Updated to NodeBB v4.3 + New Features

[NOT SOLVED] Unable to set font of the widget derived from QPlainTextEdit

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 4.8k 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.
  • S Offline
    S Offline
    soroush
    wrote on last edited by
    #3

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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #4

      I'm sorry, but what are you expected. With the code, the font was changed and qDebug output is right. So you problem is the display text's font doesn't change?

      Chuck

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soroush
        wrote on last edited by
        #5

        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!

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chuck Gao
          wrote on last edited by
          #6

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

          Chuck

          1 Reply Last reply
          0
          • S Offline
            S Offline
            soroush
            wrote on last edited by
            #7

            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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              soroush
              wrote on last edited by
              #8

              So doesn't anybody know what's happening here?
              Should I give more details or codes ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                soroush
                wrote on last edited by
                #9

                I'm still waiting....

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #10

                  @document()->setDefaultFont(myFont);@
                  The problem is that you set the font on the widget, but not the content.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    soroush
                    wrote on last edited by
                    #11

                    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.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      loladiro
                      wrote on last edited by
                      #12

                      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.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        soroush
                        wrote on last edited by
                        #13

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

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          soroush
                          wrote on last edited by
                          #14

                          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 ?

                          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