Important: Please read the Qt Code of Conduct -

WordWrap QGraphicsSimpleTextItem

  • I created a QGraphicsSimpleTextItem on my pixmapItem and set a text.
    If the text is short it is OK. but if the text is bigger than the pixmapItem width, I could not read the last part of the text.
    QGraphicsSimpleTextItem* simpleText==new QGraphicsSimpleTextItem(pixmapItem);
    fileInfo_simpleText->setText("This is long list. This is long list.");

    I was trying to find a method something like
    But it seems not exist.
    How can I wordwrap my QGraphicsSimpleTextItem in a given QRect?

  • Hi! IIRC you can get automatic word wrapping by replacing your QGraphicsSimpleTextItem with a QGraphicsTextItem.

  • @Wieland
    Thank you for the answer. QGraphicsTextItem could wrap the text as I expected. One minor concern is that when I set width, I had to do textItem->setTextWidth(geometry().width()*5.0/6) to fit the scene width. I have no idea why I have to muliply by 5/6 to fit.

Log in to reply