QGraphicsScene 中的文本 [英] Text in a QGraphicsScene

查看:64
本文介绍了QGraphicsScene 中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在QGraphicsScene的某个坐标上写文字?我试图这样做,但没有成功.文字有黑色边框,但在字母内部是白色的,我不能让它变成黑色.

How to write text in a certain cordinate in QGraphicsScene? I was trying to do like this, but with no success. Text has blck borders but inside the letters it is white, and I can't make it be black.

QPainterPath path;

QFont font;
font.setPixelSize(50);

path.addText(100, 50, font,  tr("Hello World!!!"));
path.setFillRule();

m_graphScen->addPath(path);

推荐答案

Variant 1(不好的):

Variant 1 (not a good one):

QFont font;
font.setPixelSize(10);
font.setBold(false);
font.setFamily("Calibri");

path.addText(100, 50, font,  "Hello World!!");

m_graphScen->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));

变体 2(精装版):

QGraphicsTextItem * io = new QGraphicsTextItem;
io->setPos(150,70);
io->setPlainText("Barev");

m_graphScen->addItem(io);

这篇关于QGraphicsScene 中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆