GraphicsTextItem.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "GraphicsTextItem.h"
  2. #include <QDebug>
  3. GraphicsTextItem::GraphicsTextItem(QGraphicsItem *parent)
  4. : QGraphicsTextItem(parent)
  5. {
  6. setFlag(QGraphicsItem::ItemIsMovable);
  7. setFlag(QGraphicsItem::ItemIsSelectable);
  8. setFlag(QGraphicsItem::ItemIsFocusable );
  9. setFlag(QGraphicsItem::ItemAcceptsInputMethod);
  10. }
  11. //! [0]
  12. //! [1]
  13. QVariant GraphicsTextItem::itemChange(GraphicsItemChange change,
  14. const QVariant &value)
  15. {
  16. if (change == QGraphicsItem::ItemSelectedHasChanged)
  17. emit selectedChange(this);
  18. return value;
  19. }
  20. //! [1]
  21. //! [2]
  22. void GraphicsTextItem::focusOutEvent(QFocusEvent *event)
  23. {
  24. setTextInteractionFlags(Qt::NoTextInteraction);
  25. // emit lostFocus(this);
  26. QGraphicsTextItem::focusOutEvent(event);
  27. }
  28. //! [2]
  29. //! [5]
  30. void GraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
  31. {
  32. if (textInteractionFlags() == Qt::NoTextInteraction)
  33. setTextInteractionFlags(Qt::TextEditorInteraction);
  34. QGraphicsTextItem::mouseDoubleClickEvent(event);
  35. }