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. Drag and drop tree widget item into graphicsview
Forum Updated to NodeBB v4.3 + New Features

Drag and drop tree widget item into graphicsview

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 675 Views 1 Watching
  • 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.
  • mit_cruzeM Offline
    mit_cruzeM Offline
    mit_cruze
    wrote on last edited by A Former User
    #1

    Hello, This is my simple code to drag tree-widget item. I have graphics-view in same window.
    I want to drop item into graphicsview.
    Heres my code to drag tree widget item.

    void SimplePlayer::dragEnterEvent(QDragEnterEvent *event)         //should be for graphicsview
    {
        qDebug()<<"dragEnterEvent";
        if (event->mimeData()->hasFormat("application/x-dnditemdata"))
        {
            if (event->source() == this)
            {
                event->setDropAction(Qt::MoveAction);
                event->accept();
            }
            else
            {
                event->acceptProposedAction();
            }
        }
        else
        {
            event->ignore();
        }
    
    }
    

    I am new to drag and drop. Which events are compulsory to implement?
    How do I convert tree-widget item data to turn widget after dropping into graphics-view?

    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi,
      I usually implement:

      void dragEnterEvent(QDragEnterEvent *event)
      void dragMoveEvent(QDragMoveEvent *event)
      void dropEvent(QDropEvent *event)

      In the latter you will create the GraphicsView widget item according to information that you provide at the drag source: e.g. you can serialize the essential parameters of tree-widget item into a bytearray and in the dragEvent de-serialize it and use it to create a corresponding GraphicsView widget item. Nothing of this happens automatically.

      • Michael.
      mit_cruzeM 1 Reply Last reply
      1
      • m.sueM m.sue

        Hi,
        I usually implement:

        void dragEnterEvent(QDragEnterEvent *event)
        void dragMoveEvent(QDragMoveEvent *event)
        void dropEvent(QDropEvent *event)

        In the latter you will create the GraphicsView widget item according to information that you provide at the drag source: e.g. you can serialize the essential parameters of tree-widget item into a bytearray and in the dragEvent de-serialize it and use it to create a corresponding GraphicsView widget item. Nothing of this happens automatically.

        • Michael.
        mit_cruzeM Offline
        mit_cruzeM Offline
        mit_cruze
        wrote on last edited by
        #3

        @m.sue thanks for the hint

        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