[Qt-interest] Why drag->exec() always returns 0 and I can drag?

Kermit Mei kermit.mei at gmail.com
Tue Jul 28 11:41:29 CEST 2009


Hello, community!
My code is as the following. drag->exec(Qt::MoveAction) 's return value
is always zero which means Qt::IgnoreAction.

With these code, I can't drop the objects that I want to drag. Can
anyone help me about it? And the dragEnterEvent(...) didn't run when I
drag the object.

Thanks.
Kermit Mei

attach the codes:
void IdButtonWidget::mousePressEvent(QMouseEvent *event) {
  QWidget::mousePressEvent(event);
  if(__checkable == false) {
    return ;
  }

  DPRINT("mousePressEvent");
  QPoint childPos(mapFromGlobal(event->globalPos()));
  IdButton *child = static_cast<IdButton*>(childAt(childPos));
  if (!child) {
    qDebug("No child");
    return;
  }
  selected(child);
  pressPos = event->pos();
  QPixmap pixmap = QPixmap::grabWidget(child);
  QByteArray itemData;
  QDataStream dataStream(&itemData, QIODevice::WriteOnly);
  dataStream << child->icon() << childPos << child->size() <<
child->id();

  QMimeData *mimeData = new QMimeData;
  mimeData->setData("idbutton-data", itemData);

  QDrag *drag = new QDrag(this);
  drag->setMimeData(mimeData);
  drag->setPixmap(pixmap);
  drag->setHotSpot(event->pos());

  QPixmap tempPixmap = pixmap;
  QPainter painter;
  painter.begin(&tempPixmap);
  //  painter.fillRect(pixmap.rect(), QColor(127, 127, 127,
127));                                                           
  painter.end();

  DPRINT("drag->exec() returns %d",drag->exec(Qt::MoveAction));
}







More information about the Qt-interest-old mailing list