Text in a QGraphicsScene

杀马特。学长 韩版系。学妹 提交于 2019-12-06 06:11:36

问题


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);

回答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));

Variant 2 (fine version):

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

m_graphScen->addItem(io);


来源:https://stackoverflow.com/questions/3312016/text-in-a-qgraphicsscene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!