AhealthPackButton
落在 a 上mysquare
。现在我想为这个按钮添加一个值(因为我有许多 healthPackButtons 并且我希望能够区分它们)。我尝试更改 makeDrag 函数以使其接受额外的参数,但我的 SIGNAL 不再匹配。
问题:如何将附加信息(=> int 值)传递给另一个类中的 dropEvent 处理程序。
Dialog
班级
for (int i=0; i<healthPks.size(); i++){
int value = healthPks.at(i);
QPushButton *healthPackButton = new QPushButton(title,this);
connect(healthPackButton,SIGNAL(pressed()),this,SLOT(makeDrag()));
}
void Dialog::makeDrag(){
QDrag *drag = new QDrag(this);
QMimeData *mime = new QMimeData;
mime->setText("This is a test");
drag->setMimeData(mime);
drag->start();
}
mysquare
班级
void MySquare::dropEvent(QGraphicsSceneDragDropEvent *event){
isHealthPack=true;
int xCoord = curX/width;
int yCoord = curY/height;
int value = 0; //what's the value??
const QMimeData *mimeData = event->mimeData();
emit healthMapChanged(xCoord,yCoord,value);
update();
}