现在我正在尝试创建一个文本,获取它的边界矩形,并调整它以适应盒子 – 但我不能得到包装.
class TTT: public qgraphicstextitem { TTT() { { setPlainText("abcd"); qreal x = m_itemSize.wIDth()/boundingRect().wIDth(); qreal y = m_itemSize.height()/boundingRect().height(); scale(x,y); } voID paint(QPainter* painter,const qstyleOptionGraphicsItem* option,QWidget* Widget) { // experiment with clip regions // text gets covered by hole in clip QRegion r0(boundingRect().toRect()); QRegion r1(QRect(5,5,10,10),QRegion::Ellipse); QRegion r2 = r0.subtracted(r1); painter->setClipRegion(r2); painter->setBrush(Qt::yellow); painter->drawRect(boundingRect()); qgraphicstextitem::paint(painter,option,Widget); }}
是什么让包装发生,怎么才能触发呢?
现在,当我一直打字时,该框会自动扩展.
2)是否可以将文本包装在不是矩形的QGraphicsItem / QGraphicTextItem子类中?
(如上图所示)
我试着使用clipRegion,看看上面的代码,但我想这不是正确的方法,剪切剪切文本但没有包装.
也许它会…如果我能弄清楚如何首先包装文本?
Qt 4.8
解决方法 你没有指定Qt版本,但尝试:总结voID qgraphicstextitem::setTextWIDth(qreal wIDth)
Sets the preferred wIDth for the item’s text. If the actual text is wIDer than >the specifIEd wIDth then it will be broken into multiple lines.
If wIDth is set to -1 then the text will not be broken into multiple lines >unless it is enforced through an explicit line break or a new paragraph.
The default value is -1.
以上是内存溢出为你收集整理的qt – 如何在QGraphicsItem中包装文本?全部内容,希望文章能够帮你解决qt – 如何在QGraphicsItem中包装文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)