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. Drop on QMdiArea
Qt 6.11 is out! See what's new in the release blog

Drop on QMdiArea

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

    Hi guys,

    I've subclassed a QMdiArea to accept drops. Further I've subclassed a QMdiSubWindow to setAcceptDrops to false. Despite that the subwindows accept the drops (propagate the drops to the QMdiArea) which is not desired. Here's the code (in Python):

    @
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *

    class MDIArea(QMdiArea):

    def __init__(self, parent=None):
        super(MDIArea, self).__init__(parent)
        self.setAcceptDrops(True)
    
    def add_sub_window(self, text):
        sub_window = MDISubWindow(text)
        self.addSubWindow(sub_window)
        sub_window.show()
    
    def dropEvent(self, drop_event):
        mime_data = drop_event.mimeData()
        text = unicode(mime_data.text())
        self.add_sub_window(text)
    
    def dragEnterEvent(self, event):
        event.acceptProposedAction()
    

    class MDISubWindow(QMdiSubWindow):

    def __init__(self, text, parent=None):
        super(MDISubWindow, self).__init__(parent)
        self.label = QLabel(text)
        self.setWidget(self.label)
        self.setAcceptDrops(False)
    

    class TestLabel(QLabel):

    def __init__(self, parent=None):
        super(TestLabel, self).__init__(parent)
        self.setText("Jan")
    
    def mousePressEvent(self, mouse_event):
        if mouse_event.button() == Qt.LeftButton:
            self.dragStartPosition = mouse_event.pos()
        else:
            self.mousePressEvent(mouse_event)
    
    def mouseMoveEvent(self, mouse_event):
        if mouse_event.buttons() == Qt.LeftButton:
            if (mouse_event.pos() - self.dragStartPosition).manhattanLength() < QApplication.startDragDistance():
                return
            drag = QDrag(self)
            mime_data = QMimeData()
            mime_data.setText(self.text())
            drag.setMimeData(mime_data)
            drop_action = drag.exec_(Qt.MoveAction)
        else:
            self.mousePressEvent(mouse_event)
    

    if name == "main":
    import sys

    app = QApplication(sys.argv)
    
    mdi_area = MDIArea()
    mdi_area.show()
    
    test_label = TestLabel()
    test_label.show()
    
    app.exec_()
    

    @

    Somehow I managed to get it done in prior versions but can't recall how ... (and didn't commit to vcs ... stupid me).

    Any help is highly appreciated,

    Jan

    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