Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Designing node editor widgets

    General and Desktop
    2
    3
    5727
    Loading More Posts
    • 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
      overdrivr last edited by

      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 Reply Quote 0
      • O
        overdrivr last edited by

        Anyone ?

        1 Reply Last reply Reply Quote 0
        • S
          sadaszewski last edited by

          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 Reply Quote 0
          • First post
            Last post