Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72844

REG->5.12 [Qt] Cannot drag text from QLineEdit and drop onto a widget unless setAcceptDrops is set on the drop site's parent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.1, 5.14.0 Alpha
    • 5.12.0
    • GUI: Drag and Drop
    • None
    • Windows 10 64bit Enterprise, Python3==3.6.8
    • All
    • 52e0d9e23c3f7a1b0faf6649cf3dd825bcfd4f08 (qt/qtbase/5.12.1)

    Description

      drag text from QLineEdit to QPushButton, and cannot drop the text to QPushButton.

      it seems something preventing the drop action.

      the same source code works under PySide2==5.11.2

      source code as follow:

      (an example from http://zetcode.com/gui/pyqt5/dragdrop/)

      # -*- coding: utf-8 -*-
      import sys
      
      from PySide2.QtWidgets import QPushButton, QWidget, QLineEdit, QApplication
      
      
      class Button(QPushButton):
          def __init__(self, title, parent):
              super().__init__(title, parent)
              self.setAcceptDrops(True)
      
          def dragEnterEvent(self, e):
              if e.mimeData().hasFormat('text/plain'):
                  e.accept()
              else:
                  e.ignore()
      
          def dropEvent(self, e):
              self.setText(e.mimeData().text())
      
      
      class Example(QWidget):
          def __init__(self):
              super().__init__()
              self.initUI()
              # self.setAcceptDrops(True)  # FIXME: have to use this code in PySide2==5.12.0, otherwise, drag&drop doesn't work
      
          def initUI(self):
              edit = QLineEdit('', self)
              edit.setDragEnabled(True)
              edit.move(30, 65)
      
              button = Button("Button", self)
              button.move(190, 65)
      
              self.setWindowTitle('Simple drag and drop')
              self.setGeometry(300, 300, 300, 150)
      
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
          ex = Example()
          ex.show()
          app.exec_()
      

      Attachments

        1. pyside897.py
          1 kB
        2. qtbug72844.zip
          4 kB
        3. dnd.py
          2 kB
        4. dnd.py
          2 kB

        Issue Links

          Activity

            People

              chehrlic Christian Ehrlicher
              wzzgdcn Weizhen Zheng
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: