Пример #1
0
    def mouseMoveEvent(self, event):

        if QLineF(event.screenPos(),
                  event.buttonDownScreenPos(Qt.LeftButton)).length() < QApplication.startDragDistance():
            return

        print "AtomItem::mouseMoveEvent"
        drag = QDrag(event.widget())
        mime = QMimeData()
        # A weak solution that could not be implemented in
        # C++
        mime.atom = self.atom
        mime.atom_item = self
        drag.setMimeData(mime)

        mime.setText("Atom")

        pixmap = QPixmap(int(self.boundingRect().width()),
                         int(self.boundingRect().height()))
        pixmap.fill(Qt.white)

        painter = QPainter(pixmap)
        painter.setRenderHint(QPainter.Antialiasing)

        self.paint(painter, QStyleOptionGraphicsItem(), event.widget())
        painter.end()

        pixmap.setMask(pixmap.createHeuristicMask())

        drag.setPixmap(pixmap)
        drag.setHotSpot(QPoint(int(self.boundingRect().width()/2.0), int(self.boundingRect().height()/2.0)))

        drag.exec_()
        self.setCursor(Qt.OpenHandCursor)
    def mouseMoveEvent(self, event):

        if QLineF(event.screenPos(),
                  event.buttonDownScreenPos(Qt.LeftButton)).length() < QApplication.startDragDistance():
            return

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        mime.setText("ExpressionBasedForce")

        pixmap = QPixmap(int(self.boundingRect().width()),
                         int(self.boundingRect().height()))
        pixmap.fill(Qt.white)

        painter = QPainter(pixmap)
        painter.setRenderHint(QPainter.Antialiasing)

        self.paint(painter, QStyleOptionGraphicsItem(), event.widget())
        painter.end()

        pixmap.setMask(pixmap.createHeuristicMask())

        drag.setPixmap(pixmap)
        drag.setHotSpot(QPoint(int(self.boundingRect().width()/2.0), int(self.boundingRect().height()/2.0)))

        drag.exec_()
        self.setCursor(Qt.OpenHandCursor)
Пример #3
0
    def paintEvent(self, event):
        """ A custom paint event handler which draws the image according
        to the current size constraints.

        """
        pixmap = self._pixmap
        if pixmap is None:
            return

        pm_size = pixmap.size()
        pm_width = pm_size.width()
        pm_height = pm_size.height()
        if pm_width == 0 or pm_height == 0:
            return

        width = self.size().width()
        height = self.size().height()

        if not self._scaled_contents:
            # If the image isn't scaled, it is centered if possible.
            # Otherwise, it's painted at the origin and clipped.
            paint_x = max(0, int(width / 2. - pm_width / 2.))
            paint_y = max(0, int(height / 2. - pm_height / 2.))
            paint_width = pm_width
            paint_height = pm_height
        else:
            # If the image *is* scaled, it's scaled size depends on the
            # size of the paint area as well as the other scaling flags.
            if self._preserve_aspect_ratio:
                pm_ratio = float(pm_width) / pm_height
                ratio = float(width) / height
                if ratio >= pm_ratio:
                    if self._allow_upscaling:
                        paint_height = height
                    else:
                        paint_height = min(pm_height, height)
                    paint_width = int(paint_height * pm_ratio)
                else:
                    if self._allow_upscaling:
                        paint_width = width
                    else:
                        paint_width = min(pm_width, width)
                    paint_height = int(paint_width / pm_ratio)
            else:
                if self._allow_upscaling:
                    paint_height = height
                    paint_width = width
                else:
                    paint_height = min(pm_height, height)
                    paint_width = min(pm_width, width)
            # In all cases of scaling, we know that the scaled image is
            # no larger than the paint area, and can thus be centered.
            paint_x = int(width / 2. - paint_width / 2.)
            paint_y = int(height / 2. - paint_height / 2.)

        # Finally, draw the pixmap into the calculated rect.
        painter = QPainter(self)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.drawPixmap(paint_x, paint_y, paint_width, paint_height, pixmap)
Пример #4
0
 def paintEvent(self, event):
     super().paintEvent(event)
     if self.painter is None:
         self.painter = QPainter()
     self.painter.begin(self)
     if self.image:
         self.painter.drawImage(QPoint(0, 0), self.image)
     self.painter.end()
Пример #5
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        c = QColor()
        c.setNamedColor(self._window_bgcolor)

        h, s, l, a = c.getHsl()
        c.setHsl(h, s, 100, a)

        pen = QPen(c, 8, QtCore.Qt.SolidLine)
        qp.setPen(pen)

        qp.drawRoundedRect(event.rect(), 12, 12)
        qp.end()
Пример #6
0
    def paintEvent(self, event):
        super(QMapWidget, self).paintEvent(event)

        qp = QPainter()
        qp.begin(self)
        for p in self._pix_maps:
            qp.drawPixmap(0, 0, p)
        qp.end()
Пример #7
0
 def paintEvent(self, event):
     qp = QPainter()
     qp.begin(self)
     qp.setRenderHint(QPainter.Antialiasing)
     self._draw_rim(event, qp)
     self._draw_slices(event, qp)
     self._draw_indicator(event, qp)
     qp.end()
Пример #8
0
 def paintEvent(self, event):
     qp = QPainter()
     qp.begin(self)
     qp.setRenderHint(QPainter.Antialiasing)
     self._draw_rim(event, qp)
     self._draw_slices(event, qp)
     self._draw_indicator(event, qp)
     qp.end()
Пример #9
0
    def paintEvent(self, event):
        """A custom paint event handler which draws the image according
        to the current size constraints.

        """
        pixmap = self._pixmap
        if pixmap is None:
            super().paintEvent(event)
            return

        pm_size = pixmap.size()
        pm_width = pm_size.width()
        pm_height = pm_size.height()
        if pm_width == 0 or pm_height == 0:
            super().paintEvent(event)

        width = self.size().width()
        height = self.size().height()

        if not self._scaled_contents:
            # If the image isn't scaled, it is centered if possible.
            # Otherwise, it's painted at the origin and clipped.
            paint_x = max(0, int(width / 2.0 - pm_width / 2.0))
            paint_y = max(0, int(height / 2.0 - pm_height / 2.0))
            paint_width = pm_width
            paint_height = pm_height
        else:
            # If the image *is* scaled, it's scaled size depends on the
            # size of the paint area as well as the other scaling flags.
            if self._preserve_aspect_ratio:
                pm_ratio = float(pm_width) / pm_height
                ratio = float(width) / height
                if ratio >= pm_ratio:
                    if self._allow_upscaling:
                        paint_height = height
                    else:
                        paint_height = min(pm_height, height)
                    paint_width = int(paint_height * pm_ratio)
                else:
                    if self._allow_upscaling:
                        paint_width = width
                    else:
                        paint_width = min(pm_width, width)
                    paint_height = int(paint_width / pm_ratio)
            else:
                if self._allow_upscaling:
                    paint_height = height
                    paint_width = width
                else:
                    paint_height = min(pm_height, height)
                    paint_width = min(pm_width, width)
            # In all cases of scaling, we know that the scaled image is
            # no larger than the paint area, and can thus be centered.
            paint_x = int(width / 2.0 - paint_width / 2.0)
            paint_y = int(height / 2.0 - paint_height / 2.0)

        # Finally, draw the pixmap into the calculated rect.
        painter = QPainter(self)
        painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
        painter.drawPixmap(paint_x, paint_y, paint_width, paint_height, pixmap)
Пример #10
0
    class ImageWidget(QVideoWidget):
        """Paints a QImage to the window body."""

        def __init__(self, parent=None, image_func=None):
            import numpy as np

            super().__init__(parent)
            self.image = QImage()
            self._np_image = np.zeros(shape=(0, 0, 4))
            self.painter = None
            self.resizeEvent(None)
            if image_func is None:
                # Don't bother with creating an ndarray version
                self.image_func = lambda image, bbox: image, self._np_image
            else:
                self.image_func = image_func

        def resizeEvent(self, event):
            s = self.size()
            self.width = s.width()
            self.height = s.height()

        def setImage(self, image):
            self.image, self._np_image = self.image_func(
                image, (self.width, self.height)
            )
            self.update()

        def paintEvent(self, event):
            super().paintEvent(event)
            if self.painter is None:
                self.painter = QPainter()
            self.painter.begin(self)
            if self.image:
                self.painter.drawImage(QPoint(0, 0), self.image)
            self.painter.end()
Пример #11
0
    def paintEvent(self, evt):
        # print 'paint', self.color, self.text(), self.width(), self.height(), evt.rect().width()
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(QColor('#{}'.format(self.color[:-2])))
        qp.drawRect(0, 0, self.width(), self.height())
        qp.end()

        qp.begin(self)
        qp.setPen(self._get_text_color())
        qp.drawText(evt.rect(), QtCore.Qt.AlignCenter, self.text())
        qp.end()
Пример #12
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(QColor(*self.value))
     qp.drawRect(0, 0, self.bar_width, 20)
     qp.end()
Пример #13
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(self.value)
     qp.drawRect(0, 5, self.width, self.height)
     qp.end()
Пример #14
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     self.plot_survey(qp)
     qp.end()
Пример #15
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)

        qp.setRenderHint(QPainter.Antialiasing)
        qp.setBrush(self.color)
        qp.setPen(self.color)

        rect = event.rect()
        x = rect.x()
        w = rect.width()
        lineheight = 16
        print('-------------------')
        print('lefts', self.lefts)
        print('rights', self.rights)
        print('-------------------')
        ly = self._left_y + 5
        ry = self._right_y + 5
        rs=self.rights[:]

        # offset=1
        for i, l in enumerate(self.lefts):
            path = QPainterPath()
            sl, el = l[0], l[-1]
            try:
                r=rs[i]
                sr, er = r[0], r[-1]
                rs.pop(i)
                # offset+=1
            except IndexError:
                sr, er = l[-1], l[-1]-1

            y = ly + lineheight * sl
            y2 = ry + lineheight * sr

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        for i, r in enumerate(rs):
            path = QPainterPath()
            sr, er = r[0], r[-1]
            # try:
            l=self.lefts[i]
            sl, el = r[-1], r[-1]-1
            # except IndexError:
            #     sl, el = l[-1]+2, l[-1]+1
                # print sl, el

            y = ly + lineheight * (sl)
            y2 = ry + lineheight * (sr)

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        qp.end()
Пример #16
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)

        qp.setRenderHint(QPainter.Antialiasing)
        qp.setBrush(self.color)
        qp.setPen(self.color)

        rect = event.rect()
        x = rect.x()
        w = rect.width()
        lineheight = 16
        print('-------------------')
        print('lefts', self.lefts)
        print('rights', self.rights)
        print('-------------------')
        ly = self._left_y + 5
        ry = self._right_y + 5
        rs=self.rights[:]

        # offset=1
        for i, l in enumerate(self.lefts):
            path = QPainterPath()
            sl, el = l[0], l[-1]
            try:
                r=rs[i]
                sr, er = r[0], r[-1]
                rs.pop(i)
                # offset+=1
            except IndexError:
                sr, er = l[-1], l[-1]-1

            y = ly + lineheight * sl
            y2 = ry + lineheight * sr

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        for i, r in enumerate(rs):
            path = QPainterPath()
            sr, er = r[0], r[-1]
            # try:
            l=self.lefts[i]
            sl, el = r[-1], r[-1]-1
            # except IndexError:
            #     sl, el = l[-1]+2, l[-1]+1
                # print sl, el

            y = ly + lineheight * (sl)
            y2 = ry + lineheight * (sr)

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        qp.end()
Пример #17
0
    def paintEvent(self, evt):
        # print 'paint', self.color, self.text(), self.width(), self.height(), evt.rect().width()
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(QColor('#{}'.format(self.color[:-2])))
        qp.drawRect(0, 0, self.width(), self.height())
        qp.end()

        qp.begin(self)
        qp.setPen(self._get_text_color())
        qp.drawText(evt.rect(), QtCore.Qt.AlignCenter, self.text())
        qp.end()
Пример #18
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(self.value)
     qp.drawRect(0, 5, self.width, self.height)
     qp.end()
Пример #19
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(QColor(*self.value))
     qp.drawRect(0, 0, self.bar_width, 20)
     qp.end()