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:
/*mainwindow.cpp*/
#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
this->showMaximized();
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
painter.drawPath(path);
}
/*main.cpp*/
#include "mainwindow.h"
#include <QApplication>
#include"qpainter.h"
#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);
w.setPalette(palette);
w.show();
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:
http://download.csdn.net/download/yang_quan_yang/10159005