예제 #1
0
    def do_drag(self, widget):
        """Perform the drag operation for the widget.

        Parameters
        ----------
        widget: QWidget
            A reference to the viewport widget.

        """
        drag_data = self.declaration.drag_start()
        if drag_data is None:
            return
        # widget = self.widget
        qdrag = QDrag(widget)
        qdrag.setMimeData(drag_data.mime_data.q_data())
        if drag_data.image is not None:
            qimg = get_cached_qimage(drag_data.image)
            qdrag.setPixmap(QPixmap.fromImage(qimg))
        # else:
        # if __version_info__ < (5, ):
        # qdrag.setPixmap(QPixmap.grabWidget(self.widget))
        # else:
        # qdrag.setPixmap(widget.grab())
        if drag_data.hotspot:
            qdrag.setHotSpot(QPoint(*drag_data.hotspot))
        else:
            cursor_position = widget.mapFromGlobal(QCursor.pos())
            qdrag.setHotSpot(cursor_position)
        default = Qt.DropAction(drag_data.default_drop_action)
        supported = Qt.DropActions(drag_data.supported_actions)
        qresult = qdrag.exec_(supported, default)
        self.declaration.drag_end(drag_data, DropAction(int(qresult)))
예제 #2
0
def QBrush_from_Brush(brush):
    qbrush = QBrush()
    if brush.color:
        qbrush.setColor(get_cached_qcolor(brush.color))
    if brush.image:
        qbrush.setTextureImage(get_cached_qimage(brush.image))
        qbrush.setStyle(Qt.TexturePattern)
    else:
        qbrush.setStyle(BRUSH_STYLES.get(brush.style))
    return qbrush
예제 #3
0
 def set_image(self, image):
     self.widget.setPixmap(QPixmap.fromImage(get_cached_qimage(image)))