Refresh the free text handles when the text comes back to a folio

itemChange() removed the corner handles when the text left the scene
but did not bring them back when it returned still selected, which Qt
allows (undoing a scripted delete does it) without a selection change.
Refresh on every scene change. The two handle helpers are protected:
nothing outside the class calls them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Beat Hangartner
2026-10-07 01:51:00 +02:00
parent 2989f6cb4b
commit 9882a79a93
2 changed files with 7 additions and 5 deletions
+6 -4
View File
@@ -365,17 +365,19 @@ void DiagramTextItem::focusOutEvent(QFocusEvent *event)
/**
@brief DiagramTextItem::itemChange
Show or hide the resize handles with the selection.
Show or hide the resize handles with the selection and the scene.
@param change
@param value
@return
*/
QVariant DiagramTextItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedHasChanged)
//Also when the text comes back to a scene: Qt keeps it selected
//across removeItem()/addItem() (undoing a delete) and sends no
//selection change, and its handles were removed with the scene.
if (change == QGraphicsItem::ItemSelectedHasChanged
|| change == QGraphicsItem::ItemSceneHasChanged)
refreshTextResizeHandles();
else if (change == QGraphicsItem::ItemSceneHasChanged && !scene())
removeTextResizeHandles();
return QGraphicsTextItem::itemChange(change, value);
}
+1 -1
View File
@@ -91,10 +91,10 @@ class DiagramTextItem : public QGraphicsTextItem
void setPlainText(const QString &text);
bool isHtml() const;
protected:
void refreshTextResizeHandles();
TextResizeHandles *textResizeHandles() const {return m_resize_handles;}
protected:
void paint(QPainter *,
const QStyleOptionGraphicsItem *,
QWidget *) override;