How to set font outline, font position, font style, font spacing, window background color size and hide mouse icon in QT

In qt, some attributes such as font outline, font position, font style, font spacing and window background color size are often set for font.
Here is the code to set these properties:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <QFont>
#include <QLayout>
#include <QTextCodec>

ArrowWidget::ArrowWidget(QWidget *parent)
    : QWidget(parent)
    this->setWindowFlags(Qt::FramelessWindowHint);//Remove title block
    QTextCodec::setCodecForLocale  (QTextCodec::codecForName("utf8"));//Set coding format
    resize(700,300);//Set window size

void ArrowWidget::paintEvent(QPaintEvent *event)

        int i = 100,j = 180; //str location
        QString str("ABCDE");
        QPainterPath path;
        QPen pen(Qt::black);//Outlined in black
        QPainter painter(this);

        pen.setStyle(Qt::SolidLine);//Contour is solid
        pen.setWidth(3);//Set font outline line thickness
        QFont font("Times New Roman", 100);//Set font style
        font.setLetterSpacing(QFont::PercentageSpacing,-2); //Set word spacing default 100%
        font.setLetterSpacing(QFont::AbsoluteSpacing,-4); //Default 1

        font.setBold(true);//Set bold
        path.addText(i, j, font, str);//add path
        painter.strokePath(path, pen);//set SolidLine style
        painter.fillPath(path, QBrush(Qt::white));//Font color

#include "mainwindow.h"
#include <QApplication>
#include <QPalette>
int main(int argc, char *argv[])
    QApplication a(argc, argv);
    ArrowWidget w;
    //Set the background color to red
    QPalette palette(w.palette());
    palette.setColor(QPalette::Background, Qt::red);
    return a.exec();

After the code is finally compiled, it should be migrated to the development board. If you want to hide the mouse icon and add the following parameters:
For example, after I compile the code, I generate the executable file as follows:

untitled8 -qws --nomouse

Download full project address:

Keywords: Qt

Added by reyes99 on Mon, 25 May 2020 18:09:51 +0300