You need to use QPainterPath::addText() instead of QPainter::drawText(), here is sample working code, put this into paintEvent()
QFont font
("Arial",
72,
50,
true);
pen.setWidth(2);
pen.setColor(Qt::red);
painter.setFont(font);
painter.setPen(pen);
path.addText(50, 132, font, "Hello Outline Text"); //Adjust the position
painter.drawPath(path);
QPainter painter(this);
QPainterPath path;
QPen pen;
QFont font("Arial", 72, 50, true);
pen.setWidth(2);
pen.setColor(Qt::red);
painter.setFont(font);
painter.setPen(pen);
path.addText(50, 132, font, "Hello Outline Text"); //Adjust the position
painter.drawPath(path);
To copy to clipboard, switch view to plain text mode
For further reading refer documentation
Bookmarks