2
我有一個QGraphicsPixmapItem
,我移動setFlag(QGraphicsItem::ItemIsMovable)
,我激活了ItemSendsScenePositionChanges
標誌在我的項目上,但函數itemChange(GraphicsItemChange change, const QVariant &value)
不會調用時,我移動我的項目。移動QGraphicsPixmapItem並獲取itemChange事件
任何消耗?
這裏是我的itemchange()代碼:
#include "graphicspixmapitem.h"
GraphicsPixmapItem::GraphicsPixmapItem(QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsPixmapItem(parent)
{
}
void GraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//m_clicked_signal(this);
// emit clicked();
}
void GraphicsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
//m_clicked_signal(this);
emit clicked();
}
#include <QDebug>
QVariant GraphicsPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange) {
qDebug() << "Position changed";
}
return QGraphicsItem::itemChange(change, value);
}
,這是我setFlags代碼:
QPixmap Trackinfo(":/images/ScreenContacts.png");
buf = addPixmap(Trackinfo);
buf->setPos(0, 40);
buf->setFlag(QGraphicsItem::ItemIsMovable);
buf->setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
buf->setCacheMode(QGraphicsItem::ItemCoordinateCache);
將您的代碼發佈到設置標誌和您的'itemChange(..)'方法的位置。 – cmannett85
我編輯了我的帖子以顯示問題代碼 – huston