QFont usage in Simple Terminal
-
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
-
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)
}
@ -
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>@
-
-
Hi,
IIRC, you need to use setCurrentCharFormat on your QPlainTextEdit for that.
Hope it helps
-
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);
}@
-
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.