Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QFont usage in Simple Terminal
Forum Updated to NodeBB v4.3 + New Features

QFont usage in Simple Terminal

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 2.9k 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.
  • R Offline
    R Offline
    revanth
    wrote on last edited by
    #1

    Hello,

    This is Revanth,I am beginner in Qt. I have developed a simple terminal to display it on LCD using Qt. Now i want to make changes of text font bigger. How can i make change font sizes in my simple terminal code?

    Could any one help me how to change the font sizes in Qt.

    Thank you in advance

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nologinma
      wrote on last edited by
      #2

      If in your program you don't use the UI but only the console then you cannot increase the size of the character of the console by QT but using the option of the console.

      In any case please can you share your code ?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        revanth
        wrote on last edited by
        #3

        Thank you for the reply.

        Here i used console as serial terminal and also used 'ui' for serial terminal settings.

        if possible could you please suggest me,can i use QFont in it to change the font size in it

        here i'm providing console.cpp code

        @#include "console.h"

        #include <QScrollBar>

        #include <QtCore/QDebug>

        Console::Console(QWidget *parent)
        : QPlainTextEdit(parent)
        , localEchoEnabled(false)
        {
        document()->setMaximumBlockCount(100);
        QPalette p = palette();
        p.setColor(QPalette::Base, Qt::black);
        p.setColor(QPalette::Text, Qt::green);
        setPalette(p);

        }

        void Console::putData(const QByteArray &data)
        {
        insertPlainText(QString(data));

        QScrollBar *bar = verticalScrollBar();
        bar->setValue(bar->maximum());
        

        }

        void Console::setLocalEchoEnabled(bool set)
        {
        localEchoEnabled = set;
        }

        void Console::keyPressEvent(QKeyEvent *e)
        {
        switch (e->key()) {
        case Qt::Key_Backspace:
        case Qt::Key_Left:
        case Qt::Key_Right:
        case Qt::Key_Up:
        case Qt::Key_Down:
        // skip processing
        break;
        default:
        if (localEchoEnabled)
        QPlainTextEdit::keyPressEvent(e);
        emit getData(e->text().toLocal8Bit());
        }
        }

        void Console::mousePressEvent(QMouseEvent *e)
        {
        Q_UNUSED(e)
        setFocus();
        }

        void Console::mouseDoubleClickEvent(QMouseEvent *e)
        {
        Q_UNUSED(e)
        }

        void Console::contextMenuEvent(QContextMenuEvent *e)
        {
        Q_UNUSED(e)
        }
        @

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nologinma
          wrote on last edited by
          #4

          if your want change the font of your QTextEdit you can use:

          @Console::Console(QWidget *parent)
          : QPlainTextEdit(parent)
          , localEchoEnabled(false)
          {
          document()->setMaximumBlockCount(100);
          QPalette p = palette();
          p.setColor(QPalette::Base, Qt::black);
          p.setColor(QPalette::Text, Qt::green);
          setPalette(p);

          QFont myFont("Times");
          myFont.setBold(false);
          myFont.setPointSize(24);
          
          setFont(myFont);
          

          }
          @

          don't forget:

          @#include <QFont>@

          1 Reply Last reply
          0
          • R Offline
            R Offline
            revanth
            wrote on last edited by
            #5

            i have modified the program as of your suggestion even though there is no change in font sizes.

            Although i tried using setPixelSize(int), but no alter in character size.

            Is there any other method to increase the font size in terminal?

            Thank you.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              IIRC, you need to use setCurrentCharFormat on your QPlainTextEdit for that.

              Hope it helps

              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
              0
              • N Offline
                N Offline
                nologinma
                wrote on last edited by
                #7

                Then, following the suggestion of SGaist, you have to use the following:

                @Console::Console(QWidget *parent)
                : QPlainTextEdit(parent)
                , localEchoEnabled(false)
                {
                document()->setMaximumBlockCount(100);
                QPalette p = palette();
                p.setColor(QPalette::Base, Qt::black);
                p.setColor(QPalette::Text, Qt::green);
                setPalette(p);

                QTextCharFormat ccf = currentCharFormat();
                ccf .setFontPointSize(40);
                
                setCurrentCharFormat(ccf);
                

                }@

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  revanth
                  wrote on last edited by
                  #8

                  Thank you SGaist and nologinma for helping me,

                  i have tried whatever you suggested me but its not changing in the Console terminal. Where as i tried it in other widget there i observed the font changes. But I want in Console terminal, the characters are very tiny in LCD display. So, i want it to change the font size in it.

                  Could you suggest me in any other way possible to change the font character.

                  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