各位好,我要实现的功能是,MyItem继承QGraphicsItem
class MyItem(Qpoint(x1,y1),Qpoint(x2,y2))
{
mline=qlines(Qpoint(x1,y1),Qpoint(x2,y2));
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
QRectF boundingRect() const
{
qreal penWidth = 1;
return QRectF(mline.getX1() - penWidth / 2, mline.getY1() - penWidth / 2,
mline.getX2() + penWidth, mline.getY2() + penWidth);
}
实例化MyItem *nitem=new MyItem(Qpoint(x1,y1),Qpoint(x2,y2));
scene.additem(nitem);
绘制OK,但对单独图元操作出问题了,比如想移动一个线的item 选中一个对象进行移动 结果 那个对象带动它附近其他对象一起move
还有 我想实现 鼠标hover在图元上 与鼠标按下 出现如下效果
在 Myitem的paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/ )
{
......
if(option->state & QStyle::State_Selected)
{
painter->drawRect(boundingRect()); 选中后出现矩形框,但实际实验下来 整个乱套了
}
}
请问 这个线的boundingRect() 如何计算
上图中 两个效果如何设计