コード例 #1
0
 def mouseMoveEvent(self, event):
     contains = self.grab_rect().contains(event.pos())
     if contains and not self.over_grab_hotspot:
         QtWidgets.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))
         self.over_grab_hotspot = True
     elif not contains and self.over_grab_hotspot:
         restore_cursor()
         self.over_grab_hotspot = False
コード例 #2
0
ファイル: window.py プロジェクト: MayaCommunityResources/cmt
    def mousePressEvent(self, event):
        child = self.childAt(event.pos())
        if not child:
            return
        if not isinstance(child, ComponentWidget):
            return
        pos = child.mapFromParent(event.pos())
        if not child.grab_rect().contains(pos):
            return

        # Create the drag object with the component data we are moving
        mime_data = QtCore.QMimeData()
        mime_data.setText(json.dumps(child.comp.data()))
        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        hotspot = event.pos() - child.pos()
        drag.setHotSpot(hotspot)

        # Resize the indicator so it has the same height as the ComponentWidget we are dragging
        self.drop_indicator.setFixedHeight(child.height())
        QtWidgets.qApp.setOverrideCursor(
            QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
        index = self.get_component_index_at_position(event.pos())
        component_widget_index = self.queue_layout.indexOf(child)
        self.queue_layout.takeAt(component_widget_index)
        child.hide()
        self.place_indicator(index)
        if drag.exec_(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:
            # The drag reorder was accepted so do the actual move
            drop_indicator_index = self.queue_layout.indexOf(
                self.drop_indicator)
            self.hide_indicator()
            self.queue_layout.insertWidget(drop_indicator_index, child)
            child.show()
            self.queue.clear()
            components = self.get_ordered_component_widgets()
            for widget in components:
                self.queue.add(widget.comp)
        else:
            self.queue_layout.insertWidget(component_widget_index, child)
            child.show()
        restore_cursor()