Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Designing node editor widgets
Forum Update on Monday, May 27th 2025

Designing node editor widgets

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    overdrivr
    wrote on 16 Jan 2012, 13:19 last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • O Offline
      O Offline
      overdrivr
      wrote on 22 Jan 2012, 14:24 last edited by
      #2

      Anyone ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sadaszewski
        wrote on 18 Apr 2012, 15:21 last edited by
        #3

        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/

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved