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 between two QTreeWidgets

Drag and drop between two QTreeWidgets

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.4k 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.
  • L Offline
    L Offline
    litlbear
    wrote on last edited by
    #1

    I have the following code and I can't figure out how to get it into the dropEvent() method. I can click and drag and it enters the dragEnterEvent() and when I move the cursor to the second QTreeWidget, TreeTwo) it enters the dragMoveEvent(). The Item clicked on moves between QTreeWidgets, but the program never enters the dropEvent().

    @
    import sys
    import PySide

    from PySide.QtGui import *
    from PySide import QtCore, QtGui
    from PySide.QtGui import QMainWindow
    from PySide.QtGui import QApplication
    from PySide.QtCore import *
    from mainwindow_ui import Ui_MainWindow
    import platform

    class MainWindow(QMainWindow, Ui_MainWindow, QDialog):
    def init(self, parent=None):
    super(MainWindow, self).init(parent)

    self.setupUi(self)
    self.com = communicate()

    self.com.dropinfo.connect(self.TreeTwo.dropEvent(QtCore.Qt.MoveAction))

    def somefunc():
    print 'Helloooooooooooooooooooooooo'

    def whollycrap():
    print 'Suzannnnnnnnna'

    QtGui.QTreeWidget.connect(self.TreeTwo, QtCore.SIGNAL('dropEvent()'),somefunc)
    QtGui.QTreeWidget.connect(self.TreeTwo, QtCore.SIGNAL('dragMoveEvent()'), whollycrap)
    cities = QtGui.QTreeWidgetItem(self.TreeOne)
    cities.setText(0, ('cities'))
    osloItem = QTreeWidgetItem(cities)
    osloItem.setText(0, ('Oslo'))
    osloItem.setText(1, ('Yes'))

    towns = QtGui.QTreeWidgetItem(self.TreeTwo)
    towns.setText(0, ('towns'))
    vegasItem = QTreeWidgetItem(towns)
    vegasItem.setText(0, ('Las Vegas'))
    vegasItem.setText(1, ('Yes'))

    def dragEnterEvent(self, event):
    print 'In dragEnterEvent'
    event.accept()

    def dragMoveEvent(self, event):
    print 'In dragMoveEvent'
    event.setDropAction(QtCore.Qt.MoveAction)
    event.accept()

    def dropEvent(self):
    print 'In dropEvent'

    item=self.itemAt(event.pos())

    if item: self.addHere(item)

    event.accept()

    class communicate(QtCore.QObject):
    dropinfo = QtCore.Signal()

    def buildTree(self):

    cities = QTreeWidgetItem(mainwindow_ui.TreeOne)

    cities.setText(0, tr('cities'))

    osloItem = QTreeWidgetItem(cities)

    osloItem.setText(0, tr('Oslo'))

    osloItem.setText(1, tr('Yes'))

    app = QApplication(sys.argv)
    frame = MainWindow()
    frame.show()
    app.exec_()

    @

    David

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      aren't you missing the "event" parameter in your drop event handler?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • L Offline
        L Offline
        litlbear
        wrote on last edited by
        #3

        Yes, sorry about that, I put that in and I still can't get to the dropEvent() when I drop on the second QTreeWidget.
        @
        def dropEvent(self, event):
        print 'In dropEvent'
        @

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

          Hi,

          Since you're using QTreeWidget did you check this "document":http://qt-project.org/doc/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            litlbear
            wrote on last edited by
            #5

            The documentation is quite intense for a newbie. Ok, so I have to use a mime-encoded datatype to transfer/import from one QtreeWidget to another?

            Still not sure how to do that. Any further assistance?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              litlbear
              wrote on last edited by
              #6

              Just in case, because I didn't state, I am using python and PySide.

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

                Technically you just need the "Using convenience views" part of the document.

                [quote author="litlbear" date="1376093381"]Just in case, because I didn't state, I am using python and PySide.[/quote]

                The document still applies, you only have to translate the calls from C++ to python

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

                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