How to move QGraphicsTextItem's text along with cursor.



  • How to make a QGraphicsTextItem, having constant width, to follow its cursor when the text is wider than the width of the QGraphicsTextItem?

    1. If you just create a QGraphicsTextItem and start typing text, the text item is resized to fit the text e.g. becomes wider.
    2. If you set the QGraphicsTextItem text width through setTextWidth to be > 0, then you'll get a text wrapping - the text item becomes multi-line.
    3. Subclass QGraphicsTextItem and override its boundingRect method. Return the boundingRect() calculated by the base class (QGraphicsTextItem) but set the width to a constant value before that. Now you get the behaviour of 2) without being multi-line plus the fact that the text item's viewable area doesn't follow the cursor when the text is wider than the text item.

    Please, offer a Graphics Framework class that has the same behaviour as that of QLineEdit.
    Also, make note of: https://bugreports.qt.nokia.com/browse/QTBUG-21783


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.