Python PyQt5.QtCore.QMimeData() Examples

The following are 21 code examples for showing how to use PyQt5.QtCore.QMimeData(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: linux-show-player   Author: FrancescoCeruti   File: cue_widget.py    License: GNU General Public License v3.0 6 votes vote down vote up
def mouseMoveEvent(self, event):
        if (event.buttons() == Qt.LeftButton and
                (event.modifiers() == Qt.ControlModifier or
                         event.modifiers() == Qt.ShiftModifier)):
            mime_data = QMimeData()
            mime_data.setText(PageWidget.DRAG_MAGIC)

            drag = QDrag(self)
            drag.setMimeData(mime_data)
            drag.setPixmap(self.grab(self.rect()))

            if event.modifiers() == Qt.ControlModifier:
                drag.exec_(Qt.MoveAction)
            else:
                drag.exec_(Qt.CopyAction)

            event.accept()
        else:
            event.ignore() 
Example 2
Project: pychemqt   Author: jjgomera   File: widgets.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent=None):
        super(DragButton, self).__init__(parent)

    # def mouseMoveEvent(self, event):
        # self.startDrag()
        # QtWidgets.QToolButton.mouseMoveEvent(self, event)

    # def startDrag(self):
        # if self.icon().isNull():
        #     return
        # data = QtCore.QByteArray()
        # stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
        # stream << self.icon()
        # mimeData = QtCore.QMimeData()
        # mimeData.setData("application/x-equipment", data)
        # drag = QtGui.QDrag(self)
        # drag.setMimeData(mimeData)
        # pixmap = self.icon().pixmap(24, 24)
        # drag.setHotSpot(QtCore.QPoint(12, 12))
        # drag.setPixmap(pixmap)
        # drag.exec_(QtCore.Qt.CopyAction) 
Example 3
Project: eddy   Author: danielepantaleone   File: palette.py    License: GNU General Public License v3.0 6 votes vote down vote up
def mouseMoveEvent(self, mouseEvent):
        """
        Executed when the mouse if moved while a button is being pressed.
        :type mouseEvent: QMouseEvent
        """
        if mouseEvent.buttons() & QtCore.Qt.LeftButton:
            if Item.ConceptNode <= self.item < Item.InclusionEdge:
                distance = (mouseEvent.pos() - self.startPos).manhattanLength()
                if distance >= QtWidgets.QApplication.startDragDistance():
                    mimeData = QtCore.QMimeData()
                    mimeData.setText(str(self.item.value))
                    drag = QtGui.QDrag(self)
                    drag.setMimeData(mimeData)
                    drag.setPixmap(self.icon().pixmap(60, 40))
                    drag.setHotSpot(self.startPos - self.rect().topLeft())
                    drag.exec_(QtCore.Qt.CopyAction)

        super().mouseMoveEvent(mouseEvent) 
Example 4
Project: Pythonic   Author: hANSIc99   File: basictools.py    License: GNU General Public License v3.0 6 votes vote down vote up
def mousePressEvent(self, event):

        child = self.childAt(event.pos())
        if not child:
            return

        mimeData = QMimeData()
        mimeData.setText(child.type)

        logging.debug('mousePressEvent() called: {}'.format(event.pos()))
        drag = QDrag(self)
        drag.setPixmap(child.pixmap())
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - child.pos())

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(child.pixmap()) 
Example 5
Project: Pythonic   Author: hANSIc99   File: elementmaster.py    License: GNU General Public License v3.0 6 votes vote down vote up
def mousePressEvent(self, event):
            
        logging.debug('ElementMaster::mousePressEvent() called')
        # uncomment this for debugging purpose
        #self.listChild()

        if event.buttons() != Qt.LeftButton:
            return

        icon = QLabel()

        mimeData = QMimeData()
        mime_text = str(self.row) + str(self.column) + str(self.__class__.__name__)
        mimeData.setText(mime_text)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(self.pixmap)
        drag.setHotSpot(event.pos() - self.rect().topLeft())

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            icon.close()
        else:
            icon.show()
            icon.setPixmap(self.pixmap) 
Example 6
Project: mu   Author: mu-editor   File: test_editor.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_EditorPane_drop_event(qtapp):
    """
    If there's a drop event associated with files, cause them to be passed into
    Mu's existing file loading code.
    """
    ep = mu.interface.editor.EditorPane(None, "baz")
    m = mock.MagicMock()
    ep.open_file = mock.MagicMock()
    ep.open_file.emit = m
    data = QMimeData()
    data.setUrls(
        [
            QUrl("file://test/path.py"),
            QUrl("file://test/path.hex"),
            QUrl("file://test/path.txt"),
        ]
    )
    evt = QDropEvent(
        QPointF(0, 0), Qt.CopyAction, data, Qt.LeftButton, Qt.NoModifier
    )
    ep.dropEvent(evt)
    # Upstream _load will handle invalid file type (.txt).
    assert m.call_count == 3 
Example 7
Project: CodeAtlasSublime   Author: league1991   File: CodeUIItem.py    License: Eclipse Public License 1.0 6 votes vote down vote up
def mouseMoveEvent(self, event):
		super(CodeUIItem, self).mouseMoveEvent(event)
		if self.isSelected():
			# update target positions of all dragging items
			from UIManager import UIManager
			scene = UIManager.instance().getScene()
			for uname, node in scene.itemDict.items():
				if node.isSelected():
					node.targetPos = QtCore.QPointF(node.pos().x(), node.pos().y())

		if event.buttons().__int__() & QtCore.Qt.MidButton or event.buttons().__int__() & QtCore.Qt.RightButton:
			print('event button:', event.buttons().__int__())
			drag = QtWidgets.QDrag(event.widget())
			mime = QtCore.QMimeData()
			mime.setText(self.uniqueName)
			drag.setMimeData(mime)
			drag.exec()
			#self.setCursor(QtCore.Qt.OpenHandCursor) 
Example 8
Project: Miyamoto   Author: aboood40091   File: puzzle.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mimeData(self, indexes):
        mimeData = QtCore.QMimeData()
        encodedData = QtCore.QByteArray()

        stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly)

        for index in indexes:
            if index.isValid():
                pixmap = QtGui.QPixmap(self.data(index, Qt.UserRole))
                stream << pixmap

        mimeData.setData('image/x-tile-piece', encodedData)
        return mimeData 
Example 9
Project: python   Author: Yeah-Kun   File: dragbutton.py    License: Apache License 2.0 5 votes vote down vote up
def mouseMoveEvent(self, e):

        if e.buttons() != Qt.RightButton: # 只操作右键事件
            return

        mimeData = QMimeData()

        drag = QDrag(self)  # 创建一个QDrag对象,用来传输MIME-based数据
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())

        dropAction = drag.exec_(Qt.MoveAction) 
Example 10
Project: pyNMS   Author: afourmy   File: site_panel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        # retrieve the label 
        child = self.childAt(event.pos())
        
        if not child:
            return
        
        self.controller.mode = 'selection'
        # update the creation mode to the appropriate subtype
        self.controller.creation_mode = child.subtype
        
        pixmap = QPixmap(child.pixmap().scaled(
                                            QSize(50, 50), 
                                            Qt.KeepAspectRatio,
                                            Qt.SmoothTransformation
                                            ))

        mime_data = QtCore.QMimeData()
        mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show() 
Example 11
Project: pyNMS   Author: afourmy   File: internal_node_creation_panel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        # retrieve the label 
        child = self.childAt(event.pos())
        
        if not child:
            return
        
        self.controller.mode = 'selection'
        # update the creation mode to the appropriate subtype
        self.controller.creation_mode = child.subtype
        
        pixmap = QPixmap(child.pixmap().scaled(
                                            QSize(50, 50), 
                                            Qt.KeepAspectRatio,
                                            Qt.SmoothTransformation
                                            ))

        mime_data = QtCore.QMimeData()
        mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show() 
Example 12
Project: pyNMS   Author: afourmy   File: network_node_creation_panel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        # retrieve the label 
        child = self.childAt(event.pos())
        if not child:
            return
        
        self.controller.mode = 'selection'
        # update the creation mode to the appropriate subtype
        self.controller.creation_mode = child.subtype
        # we change the view if necessary:
        # if it is a site, we switch the site view
        # if it is anything else and we are in the site view, we switch 
        # to the network view
        if child.subtype == 'site':
            self.project.show_site_view()
        else:
            if self.project.view_type == 'site':
                self.project.show_network_view()
        
        pixmap = QPixmap(child.pixmap().scaled(
                                            QSize(50, 50), 
                                            Qt.KeepAspectRatio,
                                            Qt.SmoothTransformation
                                            ))

        mime_data = QtCore.QMimeData()
        mime_data.setData('application/x-dnditemdata', QtCore.QByteArray())

        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos() + QPoint(-3, -10))

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show() 
Example 13
Project: Grabber   Author: Thomasedv   File: utilities.py    License: GNU General Public License v3.0 5 votes vote down vote up
def to_clipboard(text):
    mime = QMimeData()
    mime.setText(text)
    board = QGuiApplication.clipboard()
    board.setMimeData(mime, mode=QClipboard.Clipboard) 
Example 14
Project: Pythonic   Author: hANSIc99   File: connectivitytools.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):

        child = self.childAt(event.pos())
        if not child:
            return

        pixmap = QPixmap(child.pixmap())

        mimeData = QMimeData()
        mimeData.setText(child.type)

        drag = QDrag(self)
        drag.setPixmap(child.pixmap())
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - child.pos())

        tempPixmap = QPixmap(pixmap)
        painter = QPainter()
        painter.begin(tempPixmap)
        painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127))
        painter.end()

        child.setPixmap(tempPixmap)

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(pixmap) 
Example 15
Project: Pythonic   Author: hANSIc99   File: mltools.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):

        child = self.childAt(event.pos())
        if not child:
            return

        pixmap = QPixmap(child.pixmap())

        mimeData = QMimeData()
        mimeData.setText(child.type)

        drag = QDrag(self)
        drag.setPixmap(child.pixmap())
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - child.pos())

        tempPixmap = QPixmap(pixmap)
        painter = QPainter()
        painter.begin(tempPixmap)
        painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127))
        painter.end()

        child.setPixmap(tempPixmap)

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(pixmap) 
Example 16
Project: Pythonic   Author: hANSIc99   File: dropbox.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        
        logging.debug('DropBox::mousePressEvent() called: {}'.format(event.pos()))
        try:
            mimeData = QMimeData()
            mimeData.setText(self.type)
            # load config into memory tmp_config of storabar
            self.parent.tmp_config = self.config
            self.parent.tmp_element = self
            # push config to active workingarea
            self.parent.loadConfig() 
        except Exception as e:
            logging.error('DropBox::mousePressEvent() Exception caught: {}'.format(str(e)))
            return

        drag = QDrag(self)
        drag.setHotSpot(event.pos())
        drag.setPixmap(self.label.pixmap())
        drag.setMimeData(mimeData)

        if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
            self.close()
        else:
            self.show()
            self.label.setPixmap(self.label.pixmap())
            logging.debug('DropBox::mousePressEvent() dropped') 
Example 17
Project: PyQt   Author: PyQt5   File: Custom_DND_image.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent_xxx(self, e):
        mimeData = QtCore.QMimeData()
        drag = QDrag(self)
        drag.setMimeData(mimeData)

        # pixmap = QPixmap()
        # drag.setPixmap(pixmap)

        # drag.setHotSpot(e.pos())

        # QTreeWidget.mouseMoveEvent(self,e)
        drag.exec_(QtCore.Qt.MoveAction) 
Example 18
Project: urh   Author: jopohl   File: SignalFrame.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.drag_started.emit(self.mapToParent(event.pos()))
            drag = QDrag(self)
            mimeData = QMimeData()
            mimeData.setText("Move Signal")
            pixmap = QPixmap(self.rect().size())
            self.render(pixmap, QPoint(), QRegion(self.rect()))
            drag.setPixmap(pixmap)

            drag.setMimeData(mimeData)

            drag.exec_() 
Example 19
Project: urh   Author: jopohl   File: ProtocolTreeModel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mimeData(self, indexes):
        data = ''
        for index in indexes:
            parent_item = self.getItem(index.parent())
            if parent_item == self.rootItem:
                data += "{0},{1},{2}/".format(index.row(), index.column(), -1)
            else:
                data += "{0},{1},{2}/".format(index.row(), index.column(), self.rootItem.index_of(parent_item))
        mime_data = QMimeData()
        mime_data.setText(data)
        return mime_data 
Example 20
Project: asammdf   Author: danielhrisca   File: tree_numeric.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def startDrag(self, supportedActions):
        selected_items = self.selectedItems()

        mimeData = QtCore.QMimeData()

        data = []

        for item in selected_items:

            entry = item.entry

            if entry == (-1, -1):
                info = {
                    "name": item.name,
                    "computation": {},
                }
                info = json.dumps(info).encode("utf-8")
            else:
                info = item.name.encode("utf-8")

            data.append(
                pack(
                    f"<36s3q{len(info)}s",
                    str(item.mdf_uuid).encode("ascii"),
                    entry[0],
                    entry[1],
                    len(info),
                    info,
                )
            )

        mimeData.setData(
            "application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data))
        )

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.exec(QtCore.Qt.CopyAction) 
Example 21
Project: asammdf   Author: danielhrisca   File: list.py    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
def startDrag(self, supportedActions):
        selected_items = self.selectedItems()

        mimeData = QtCore.QMimeData()

        data = []

        for item in selected_items:

            entry = item.entry
            computation = item.computation

            widget = self.itemWidget(item)

            color = widget.color
            unit = widget.unit

            if entry == (-1, -1):
                info = {
                    "name": item.name,
                    "computation": computation,
                    "computed": True,
                    "unit": unit,
                    "color": color,
                }
                info = json.dumps(info).encode("utf-8")
            else:
                info = item.name.encode("utf-8")

            data.append(
                pack(
                    f"<36s3q{len(info)}s",
                    str(item.mdf_uuid).encode("ascii"),
                    entry[0],
                    entry[1],
                    len(info),
                    info,
                )
            )

        mimeData.setData(
            "application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data))
        )

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.exec(QtCore.Qt.CopyAction)