Drag and drop from QToolBar to QGraphicsView is not working properly
-
I am working on a project using
Qt C++. I have aQToolBarwhich contains someQButtons (read asQAction) and aQGraphicsView(the whole bottom part).
It looks like this.Now, I want to drag a
QButton(read asQAction) from theQToolBarinto central window (which actually isQGraphicsView) of my application.Till now I have written the following
SLOTfor correspondingQActionto enable dragging and dropping./* Send_Message is one of the actions */ void CTestBuilderApp::on_actionSend_Message_triggered() { QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); emit selectionState(None); dataStream << "Send Message"; QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-dnditemdata", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(ui->ToolBox->actions().at->icon().pixmap(48,48)); drag->exec(Qt::CopyAction, Qt::CopyAction); qDebug()<<"drag complete"; }But, as this
SLOTis being called only when I amclicking on theQAction, I am not getting the proper effect of Drag and Drop. When I am clicking the button, only then the dragging is starting. One click on theQActionand then another click onQGraphicsViewis doing the job, but it's not what it's supposed to be for drag & drop. It's not starting on pressing and then dragging.Is there any way out to make this code work? I am searching for some
SLOTthat get called as soon as I press on theQActioni.e. it does not wait for Mouse Release to work. -
Hi,
If you want to customise the drag and drop you'll need to either use a custom QToolBar implementing the technique described in the Drag and Drop documentation.
