[Qt-interest] Allowing Panning of QGraphicsItem AND Drag/Drop to another QGraphicsView

Anton Chernov mechernov at gmail.com
Tue Apr 12 22:21:25 CEST 2011


Read
http://doc.qt.nokia.com/latest/dnd.html

dragMoveEvent should be not in the item but in the view. To have an image
been draged call setPixmap on the QDrag object. If you want to have visible
only what you are draging call hide on the item in mousePressEvent.

Something like
void View::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton
  && "selectedItems" ) {

QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;

  mimeData->setText( "selectedItems->text()" );
drag->setMimeData(mimeData);
drag->setPixmap(iconPixmap);

"selectedItems->hide()"

Qt::DropAction dropAction = drag->exec();
if(dropAction == Qt::IgnoreAction) {
"selectedItems->showAgain()";
}
}
}

2011/4/8 Cole, Derek <dcole at integrity-apps.com>

>  Hello,
>
> I have subclassed a QGraphicsItem to allow for some custom interaction of
> these large images I have showing in my QGraphicsView. I wanted to allow for
> zooming and panning of multiple large images in a fixed size viewport, so I
> modified the mouseRelease and mousePress events to modify the position of
> the QGraphicsItem, and I modified the wheelevent to allow a person to zoom
> in or out on the individual image, instead of the entire scene.
>
> I want to allow a person to move this QGraphicsItem completely out of the
> current QGraphicsView and into another one. Would this be accomplished by
> overriding the dragMoveEvent of the object that I want to move? I am a
> little unclear on how this is supposed to work. In the destination
> QGraphicsView do I just have to set it to accept drops, and it will
> automatically get the image, if I can get the dragging part working?
>
> Thanks
>
> Derek
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110412/a8725fea/attachment.html 


More information about the Qt-interest-old mailing list