开发者

Text in a QGraphicsScene

开发者 https://www.devze.com 2023-01-08 05:25 出处:网络
How to write text in a certain cordinate in QGraphicsScene? I was trying to do like this, but with no success. Text has black borders but inside the letters 开发者_如何转开发it is white, and I can\'t

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

    QPainterPath path;

    QFont font;
    font.setPixelSize(50);

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

    m_graphScen->addPath(path);


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

精彩评论

暂无评论...
验证码 换一张
取 消