【问题标题】:how to change the text added to the scene?如何更改添加到场景中的文本?
【发布时间】:2014-07-03 16:05:51
【问题描述】:

我想在我的场景中添加文本。有时应该更改此文本。如何更改添加到场景中的文本?假设我有一个获得积分的玩家,我将他的积分放在我的场景中。当他的积分增加或减少时,我必须更改文本。如何做这项工作?

QString points;
QGraphicsTextItem* text;
QFont font;
font.setBold(true);
font.setPointSize(50);
font.setItalic(true);
te="Ponit";
text=scene->addText(points,font);
text->setPos(100,100);
text->setDefaultTextColor(QColor("red"));

【问题讨论】:

  • 您有QGraphicsTextItem *text;,因此您只需致电QGraphicsTextItem::setPlainText(const QString & text) 即可更改文本。

标签: qt qgraphicsscene


【解决方案1】:

当您调用QGraphicsScene::addText 时,它会返回QGraphicsTextItem。使用此对象,您可以设置plainHTML 文本。例如:-

text->setPlainText("Some New Text");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 2021-08-11
    • 2016-02-26
    相关资源
    最近更新 更多