2013-05-19 58 views
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); 
+0

將您的代碼發佈到設置標誌和您的'itemChange(..)'方法的位置。 – cmannett85

+0

我編輯了我的帖子以顯示問題代碼 – huston

回答

1

你有沒有打過電話的QGraphicsItem :: mousePressEvent和的QGraphicsItem的默認實現: :mouseReleaseEvent對你的物品的mousePressEvent和mouseReleaseEvent?

如果你不打電話給他們,我懷疑你甚至不能用鼠標移動物品,因爲你不讓Qt知道物品何時被點擊/釋放。

相關問題