【发布时间】:2015-07-08 11:30:00
【问题描述】:
我已经创建了一个从 QGraphicsRectItem 派生的自定义类。
class CornerPoint : public QGraphicsRectItem
{
public:
CornerPoint(QPointF centre);
enum { Type = UserType + 1 };
int type() const{ return Type; }
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
public slots:
void updatePosition(QPointF);
};
CPP 文件
CornerPoint::CornerPoint(QPointF centre): QGraphicsRectItem(NULL)
{
setPos(55,22);
setRect(0,0,99,99);
}
QVariant CornerPoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
std::cout << "Change is" << change << std::endl;
if( QGraphicsItem::ItemPositionChange == change && scene())
{
std::cout << "New values " << value.toPointF().x() << value.toPointF().y() << std::endl;
}
return QGraphicsItem::itemChange(change, value);
}
我已将这些对象设为可选择和可移动的。但是当我拖动它们时,我没有收到这个矩形位置变化的信号。我收到的只是值为 4 (ItemSelectedChange) 和 14 (ItemSelectedHasChanged) 的信号。
This post 说我需要启用一些标志。但是我找不到任何人这样做的任何例子,并且使用这些标志会出错。
【问题讨论】:
标签: qt qt5 qgraphicsview qgraphicsitem qgraphicsscene