C++ (Qt) bool sceneEvent (QEvent *event) { if (event->type() == QEvent::UngrabMouse) emit itemDropped(); return QGraphicsRectItem::sceneEvent(event); }
connect(item[15],SIGNAL(itemDropped()),this,SLOT(Move()));
void MainWindowImpl::Move(){ if(item[15]->collidesWithItem(line[3])){ item[15]->setRect(QRectF(-225.0+5*15, 260.0-25*n2, 190.0-10*15, 25.0)); } if(item[15]->collidesWithItem(line[5])){ item[15]->setRect(QRectF(155.0+5*15, 260.0-25*n3, 190.0-10*15, 25.0));}}
qobject_cast<MyGraphicsRectItem *>(sender())
MyGraphicsRectItem *items=qobject_cast<MyGraphicsRectItem *>(sender());
void MainWindowImpl::Move(){ MyGraphicsRectItem *currItem = qobject_cast<MyGraphicsRectItem *>(sender()); qDebug() << currItem->pos();//...}
void MainWindowImpl::Move(){ MyGraphicsRectItem *items=qobject_cast<MyGraphicsRectItem *>(sender());items()->setPos(-75+5*15, 350.0-25*(n1-1));}
items->setPos(-75+5*15, 350.0-25*(n1-1));
QTimer::singleShot(1000, this, SLOT(Caption()));