hi i solve it, but only partly
Qt Code:
  1. HandleItem::HandleItem( QGraphicsItem *item, QGraphicsScene *scene,
  2. QColor color, HandleItem::HandleRole role,
  3. QList<HandleItem*> handles ) : QGraphicsItem( 0, scene )
  4. {
  5. m_role = role;
  6. m_color = color;
  7. m_item = item;
  8. m_handles = handles;
  9. m_pressed = false;
  10. setZValue( 100 );
  11. setFlag( ItemIsMovable );
  12. }
  13.  
  14. QRectF HandleItem::boundingRect() const
  15. {
  16. QPointF point = m_item->boundingRect().center();
  17. switch( m_role ){
  18. case CenterHandle:
  19. return QRectF( point-QPointF(5, 5), QSize( 10, 10 ) );
  20. case RightHandle:
  21. point.setX( m_item->boundingRect().right() );
  22. return QRectF( point-QPointF(3, 5), QSize( 6, 10 ) );
  23. case TopHandle:
  24. point.setY( m_item->boundingRect().top() );
  25. return QRectF( point-QPointF(5, 3), QSize( 10, 6 ) );
  26. }
  27. return QRectF();
  28. }
  29.  
  30. void HandleItem::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget )
  31. {
  32. paint->setPen( m_color );
  33. paint->setBrush( m_color );
  34. QRectF rect = boundingRect();
  35. QVector<QPointF> points;
  36. switch( m_role ){
  37. case CenterHandle:
  38. paint->drawEllipse( rect );
  39. break;
  40. case RightHandle:
  41. points << rect.center()+QPointF(3,0) << rect.center()+QPointF(-3,-5) << rect.center()+QPointF(-3,5);
  42. paint->drawConvexPolygon( QPolygonF(points) );
  43. break;
  44. case TopHandle:
  45. points << rect.center()+QPointF(0,-3) << rect.center()+QPointF(-5,3) << rect.center()+QPointF(5,3);
  46. paint->drawConvexPolygon( QPolygonF(points) );
  47. break;
  48. }
  49. }
  50.  
  51. void HandleItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
  52. {
  53. m_pressed = true;
  54. QGraphicsItem::mousePressEvent( event );
  55. }
  56. void HandleItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
  57. {
  58. m_pressed = false;
  59. QGraphicsItem::mouseReleaseEvent( event );
  60. }
  61.  
  62. QVariant HandleItem::itemChange( GraphicsItemChange change, const QVariant &data )
  63. {
  64. if( change == ItemPositionChange && m_pressed ){
  65. QPointF movement = data.toPoint() - pos();
  66. QPointF center = m_item->boundingRect().center();
  67. switch( m_role ){
  68. case CenterHandle:
  69. m_item->moveBy( movement.x(), movement.y() );
  70. foreach( HandleItem *handle, m_handles )
  71. handle->translate( movement.x(), movement.y() );
  72. break;
  73. case TopHandle:
  74. if( -2*movement.y() + m_item->sceneBoundingRect().height() <= 5 )
  75. return QGraphicsItem::itemChange( change, pos() );
  76. movement.setX( 0 );
  77. m_item->translate( center.x(), center.y() );
  78. m_item->scale( 1, 1.0-2.0*movement.y() /(m_item->sceneBoundingRect().height()) );
  79. m_item->translate( -center.x(), -center.y() );
  80. break;
  81. case RightHandle:
  82. if( 2*movement.x() + m_item->sceneBoundingRect().width() <= 5 )
  83. return QGraphicsItem::itemChange( change, pos() );
  84. movement.setY( 0 );
  85. m_item->translate( center.x(), center.y() );
  86. m_item->scale( 1.0+2.0*movement.x()/(m_item->sceneBoundingRect().width()), 1 );
  87. m_item->translate( -center.x(), -center.y() );
  88. break;
  89. }
  90. return QGraphicsItem::itemChange( change, pos()+movement );
  91. }
  92. return QGraphicsItem::itemChange( change, data );
  93. }
To copy to clipboard, switch view to plain text mode 
class:
Qt Code:
  1. class HandleItem : public QGraphicsItem
  2. {
  3. public:
  4. enum HandleRole { CenterHandle, RightHandle, TopHandle };
  5.  
  6. HandleItem( QGraphicsItem *item, QGraphicsScene *scene,
  7. QColor color, HandleRole role = CenterHandle,
  8. QList<HandleItem*> handles = QList<HandleItem*>() );
  9.  
  10. void paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget );
  11. QRectF boundingRect() const;
  12.  
  13. protected:
  14. void mousePressEvent( QGraphicsSceneMouseEvent *event );
  15. void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
  16. QVariant itemChange( GraphicsItemChange change, const QVariant &data );
  17.  
  18. private:
  19. QGraphicsItem *m_item;
  20. HandleRole m_role;
  21. QColor m_color;
  22. QList<HandleItem*> m_handles;
  23. bool m_pressed;
  24. };
To copy to clipboard, switch view to plain text mode 
It is OK, but I dont know how translate coordition system to my item has CenterHandle, TopHandle and RightHandle at same pocition...
When I get mouseClick into my item CenterHandle, TopHandle and RightHandle are set well, I get mouse click next to my item CenterHandle, TopHandle and RightHandle are removed. It is OK. If I get mouseClick into my item CenterHandle, TopHandle and RightHandle are set and then I want to move my item. It is OK too. Then I click next to my item. It is OK. Then I want to move my item again, so I click into my item, but CenterHandle, TopHandle and RightHandle are set at first position(so I isnt in my item)

So I would like to ask, how I set translate or something else my item, when I change position of item.

Thanks a lot and sorry for my simple english