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.

    1. 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.

    2. What does QDragEnterEvent::setDropAction(Qt::MoveAction) ?

    3. 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();
    }
    

    }@

    1. 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&#40;Qt::CopyAction | Qt::MoveAction, Qt::CopyAction&#41; == Qt::MoveAction&#41;
        child->close();
    else
    {
        child->show();
        child->setPixmap(pixmap);
    }
    

    }@

    Thanks for any help !



  • Anyone ?



  • 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/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.