我有一个从 QGraphicsPixmapItem 派生的自定义类。它称为 GraphPixmapItemCustom ,它的重载方法是:
void GraphPixmapItemCustom::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsPixmapItem::mousePressEvent(event);
GraphMarkItemCustom *ptr;
if(event->button() == Qt::RightButton)
{
qDebug("Before emit");
emit addPoint(QPointF(event->pos().x(), event->pos().y()));
qDebug("After emit");
markList.append(new GraphMarkItemCustom(QPointF(event->pos().x(), event->pos().y())));
ptr = markList.last();
markGroup->addToGroup(ptr);
//this->scene()->addItem(ptr);
}
}
信号在标题中声明:
signals:
void addPoint(QPointF position);
在具有指向类 GraphPixmapItemCustom 对象的指针的主类中
private:
GraphPixmapItemCustom *pixItemRGB;
在主类中,我有一个名为:
private slots:
void pointAdd(QPointF position);
在主类构造函数中,我有一个连接:
connect(pixItemRGB, SIGNAL(addPoint(QPointF)), this, SLOT(pointAdd(QPointF)));
在插槽中我只有qDebug("YUPPY IT ACTUALLY WORKS!");
但是该插槽没有被解雇。为什么?我已经删除了所有 moc 文件和所有不需要的东西。所以只有.pro
,.h
和.cpp
文件以及需要.ui
留下的表格。
我检查了谷歌的大多数点击。什么是最好的(我不确定 - 也许我修改了一些东西)它起作用了!我记得这种连接的工作效果。帮助!