【发布时间】:2012-12-20 11:39:02
【问题描述】:
healthPackButton 被丢弃在 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();
}
【问题讨论】:
标签: c++ qt drag-and-drop