Designing node editor widgets
-
Hi all,
I'm trying to code what I call a node editor with Qt (look blender node editor to get an idea). I've looked the example (draggable icons), and I've got some questions.
-
I'm wondering what is the "application/x-dnditemdata" format for the Mime-data. I looked in the doc, found nothing but I may have missed it.
-
What does QDragEnterEvent::setDropAction(Qt::MoveAction) ?
-
In the implementation of dropEvent(QDropEvent *event) in the example, why do we need to make a copy of the draggable QLabel pixmap, move the copy and then show() it, instead of just moving the original QLabel ? That seems a bit wasting ressources.
@void NodesWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("application/x-dnditemdata"))
{
QByteArray itemData = event->mimeData()->data("application/x-dnditemdata");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);QPixmap pixmap; QPoint offset; dataStream >> pixmap >> offset; QLabel *newIcon = new QLabel(this); newIcon->setPixmap(pixmap); newIcon->move(event->pos() - offset); newIcon->show(); newIcon->setAttribute(Qt::WA_DeleteOnClose); if (event->source() == this) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else { event->ignore(); }
}@
- I don't want to display a greyish version of the original QLabel at the original position, how should I modify this code to remove that ? Some parts of this code is little bit obscure to me
@void NodesWidget::mousePressEvent(QMouseEvent *event)
{
//On recupere le widget concerné par l'event (qui est un enfant de la fenetre actuelle)
QLabel child = static_cast<QLabel>(childAt(event->pos()));
if (!child)
return;//On copie son image QPixmap pixmap = *child->pixmap(); //?? QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << pixmap << QPoint(event->pos() - child->pos()); //?? QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-dnditemdata", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos() - child->pos()); QPixmap tempPixmap = pixmap; QPainter painter; painter.begin(&tempPixmap); painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)); painter.end(); child->setPixmap(tempPixmap); if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) child->close(); else { child->show(); child->setPixmap(pixmap); }
}@
Thanks for any help !
-
-
It's not a reply to your questions but maybe you will find it useful : http://algoholic.eu/qnodeseditor-qt-nodesports-based-data-processing-flow-editor/