2

アイテムのフラグを有効にしましたが、アイテムをQGraphicsPixmapItem移動しても関数が呼び出されません。setFlag(QGraphicsItem::ItemIsMovable)ItemSendsScenePositionChangesitemChange(GraphicsItemChange change, const QVariant &value)

何か提案はありますか?

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);
4

1 に答える 1