【问题标题】:Qt allignment of a QGraphicsSimpleTextItem in a QGraphicsSceneQGraphicsScene 中 QGraphicsSimpleTextItem 的 Qt 对齐
【发布时间】:2015-12-27 03:29:14
【问题描述】:

我想在图形场景中添加一个简单的文本项(一个单词),因此使用 QGraphicsSimpleTextItem。文本项的场景坐标定义了文本的左上角。

是否可以让文本中心围绕坐标对齐?

【问题讨论】:

    标签: qt5.5


    【解决方案1】:

    为此使用 setPos()。例如,其中 (X,Y) 是文本必须对齐的中心点:

    QGraphicsSimpleTextItem *Item;
    Item->setText( QString::fromLatin1( "My text" ) );
    QRectF bR = Item->sceneBoundingRect();
    Item->setPos( X - bR.width()/2, Y - bR.height()/2 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多