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. Please help,Drag and drop to a QgraphicsView
Forum Updated to NodeBB v4.3 + New Features

Please help,Drag and drop to a QgraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 149 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.
  • E Offline
    E Offline
    electric-dev
    wrote last edited by
    #1

    Hello, good morning everyone. I am trying to implement drag and drop from a widget(QPushbutton) located in a QFrame to a view (QgraphicsView), but I am unable to do so. The idea is that when I drag the widget to the view and drop it there, an item (QgraphicsItem) that I call My_Node appears,but nothing happen

    Below is part of the code.I hope you can help me.

    # this is the widget in the QFrame
    
    class Button(QPushButton):
        def __init__(self):
            super().__init__()
            
            self.setText("2025")
    
        def mouseMoveEvent(self, event):
            if event.buttons() == Qt.LeftButton:
    
                drag = QDrag(self)
                mime = QMimeData()
                drag.setMimeData(mime)
                drag.exec(Qt.DropAction.MoveAction)
    
    # This is part of the view code
    
    class My_view(QGraphicsView):
        def __init__(self,parent):
         super().__init__(parent)
    
         
         self.setAcceptDrops(True)
         self.my_scene=My_scene()
         self.setScene(self.my_scene)
       
    
        def dragEnterEvent(self, event):
    
          event.acceptProposedAction()
          
          
        def dropEvent(self,event):
    
          self.mi_nodo=My_Node()
    
          self.my_scene.addItem(self.mi_nodo) 
    
          event.acceptProposedAction()
    
    JonBJ 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Pretty simply: add debug statements for example to see if your methods are called. You can also trigger the debugger if you want to see in details what is going on.
      Next you did not implement the dragMove event.

      E Offline
      E Offline
      electric-dev
      wrote last edited by
      #5

      @SGaist thank you so much ,now it works, all that was missing was the QDragMoveEvent.

      1 Reply Last reply
      0
      • E electric-dev

        Hello, good morning everyone. I am trying to implement drag and drop from a widget(QPushbutton) located in a QFrame to a view (QgraphicsView), but I am unable to do so. The idea is that when I drag the widget to the view and drop it there, an item (QgraphicsItem) that I call My_Node appears,but nothing happen

        Below is part of the code.I hope you can help me.

        # this is the widget in the QFrame
        
        class Button(QPushButton):
            def __init__(self):
                super().__init__()
                
                self.setText("2025")
        
            def mouseMoveEvent(self, event):
                if event.buttons() == Qt.LeftButton:
        
                    drag = QDrag(self)
                    mime = QMimeData()
                    drag.setMimeData(mime)
                    drag.exec(Qt.DropAction.MoveAction)
        
        # This is part of the view code
        
        class My_view(QGraphicsView):
            def __init__(self,parent):
             super().__init__(parent)
        
             
             self.setAcceptDrops(True)
             self.my_scene=My_scene()
             self.setScene(self.my_scene)
           
        
            def dragEnterEvent(self, event):
        
              event.acceptProposedAction()
              
              
            def dropEvent(self,event):
        
              self.mi_nodo=My_Node()
        
              self.my_scene.addItem(self.mi_nodo) 
        
              event.acceptProposedAction()
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote last edited by
        #2

        @electric-dev
        Why did you delete your identical question at https://forum.qt.io/topic/163406/drag-and-drop-to-a-qgraphicsview, which I replied to and asked you

        And what happens? Are you going to tell us whether either your dragEnterEvent() or dropEvent() are ever called?

        E 1 Reply Last reply
        1
        • JonBJ JonB

          @electric-dev
          Why did you delete your identical question at https://forum.qt.io/topic/163406/drag-and-drop-to-a-qgraphicsview, which I replied to and asked you

          And what happens? Are you going to tell us whether either your dragEnterEvent() or dropEvent() are ever called?

          E Offline
          E Offline
          electric-dev
          wrote last edited by
          #3

          @JonB Hello, good evening. I deleted the previous post because I couldn't update the information as you had recommended. A message appeared on the page saying that I had to wait 3600 seconds to make changes to the post, so I waited, but the same message kept appearing.

          Regarding this, “And what happens? Are you going to tell us whether either your dragEnterEvent() or dropEvent() are ever called?”, I believe that the dragEnterEvent() and dropEvent() events are implemented in the My_View class, but if this is not the case and it is not too much trouble, please let me know how to do it.

          Translated with DeepL.com (free version)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #4

            Hi,

            Pretty simply: add debug statements for example to see if your methods are called. You can also trigger the debugger if you want to see in details what is going on.
            Next you did not implement the dragMove event.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            E 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              Pretty simply: add debug statements for example to see if your methods are called. You can also trigger the debugger if you want to see in details what is going on.
              Next you did not implement the dragMove event.

              E Offline
              E Offline
              electric-dev
              wrote last edited by
              #5

              @SGaist thank you so much ,now it works, all that was missing was the QDragMoveEvent.

              1 Reply Last reply
              0
              • E electric-dev has marked this topic as solved

              • Login

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