79188686

Date: 2024-11-14 12:14:27
Score: 0.5
Natty:
Report link

It looks like I've started to figure out how to do what I need to do. Added the following lines to the "customTable" class:

        # Custom headers
    HH = customQHeaderView(parent = self, orientation=Qt.Horizontal)
    VH = customQHeaderView(parent = self, orientation=Qt.Vertical)

    self.setHorizontalHeader(HH)
    self.setVerticalHeader(VH)

And added new class "customQHeaderView":

class customQHeaderView(QHeaderView):
MimeType = 'application/x-qabstractitemmodeldatalist'

def __init__(self, orientation: Qt.Orientation, parent=None):
    super().__init__(orientation, parent)
    self.setDragEnabled(True)
    self.setAcceptDrops(True)

def dropEvent(self, event):
    mimedata = event.mimeData()
    if mimedata.hasFormat(customQHeaderView.MimeType):
        if event.source() is not self:
            source_item = QStandardItemModel()
            source_item.dropMimeData(mimedata, Qt.CopyAction, 0,0, QModelIndex())
            label = source_item.item(0, 0).text()
            print(label)
            event.setDropAction(Qt.MoveAction)
            event.accept()
        else:
            event.ignore()
    else:
        super().dropEvent(event)
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: z3r0cr33d