Qt-interest Archive, April 2008
this drag works in Linux but not in windows (with Qt 4.3.2)
Message 1 in thread
I have a problem with dragging with Qt in windows.
The program in linux works in this way (I wrote a short example of my code
below) :
I press a QPushButton (pbForm) and it calls a function named startToolDrag(int
tool). In the startToolDrag(int tool) function, the drag is started. It
works fine.
But in windows with the same code, when I press the button pbForm and the
function startToolDrag(int tool) is called, the drag doesn't look to work.
The only way to make it work is maintening pressed the left button of the
mouse and then press the right button (of the mouse) over the pbForm. It seem
like drags is not generated, or dropped fastly. The drop is called until I
release the left button of the mouse.
do you have any idea how to solve this problem?
Thanks in advantage for your ideas and your time.
-------------
BEGIN EXAMPLE CODE
-------------
void Form::on_pbForm_clicked()
{
startToolDrag(Constants::TASK_FORM);
}
void Form::startToolDrag(int tool){
QPixmap pixmap;
QDrag *drag;
QMimeData *mimeData;
drag = new QDrag(this);
mimeData = new QMimeData;
mimeData->setText(QString::number(tool));
drag->setMimeData(mimeData);
switch (tool) {
case Constants::TASK_FORM:
pixmap = QPixmap(":/image/form.png");
break;
...
}
drag->setPixmap(pixmap);
Qt::DropAction dropAction = drag->start();
}
void Editor::dragEnterEvent ( QGraphicsSceneDragDropEvent * event )
{
if (event->mimeData()->hasFormat("text/plain"))
event->acceptProposedAction();
}
void Editor::dragMoveEvent ( QGraphicsSceneDragDropEvent * event )
{
m_isDragging = true;
m_dragPos = event->scenePos();
}
void Editor::dropEvent ( QGraphicsSceneDragDropEvent * event )
{
int tipo;
QString accion;
bool ok;
m_isDragging = false;
accion = event->mimeData()->text();
event->acceptProposedAction();
ok = false;
tipo = accion.toInt(&ok);
if (!ok)
return;
switch (tipo) {
case Constants::TASK_FORM:
...
break;
...
}
QGraphicsScene::dropEvent(event);
}
----------------
-END EXAMPLE CODE
----------------
--
[ signature omitted ]