For Qt 4.6.x, how to auto-size text to fit in a specified width?

前端 未结 8 1198
情书的邮戳
情书的邮戳 2020-12-31 04:11

Inside of my QGraphicsRectItem::paint(), I am trying to draw the name of the item within its rect(). However, for each of the different items, they can be of variable width

8条回答
  •  天命终不由人
    2020-12-31 04:36

    You could have a QGraphicsTextItem as a child of the rect item, measure the text item's width and then scale the text item (setTransform()) to fit into the rect item's width (and height).

提交回复
热议问题