当前位置: 首页>>代码示例>>Python>>正文


Python QGraphicsEllipseItem.setPos方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QGraphicsEllipseItem.setPos方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsEllipseItem.setPos方法的具体用法?Python QGraphicsEllipseItem.setPos怎么用?Python QGraphicsEllipseItem.setPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QGraphicsEllipseItem的用法示例。


在下文中一共展示了QGraphicsEllipseItem.setPos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DraggedLineItem

# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPos [as 别名]
class DraggedLineItem(QGraphicsPathItem):

    def __init__(self, p0, p1, parent=None):
        QGraphicsPathItem.__init__(self, parent=parent)

        self._p0 = p0
        self._p1 = p1

        self._startPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._startPoint.setPos(p0)
        self._endPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._endPoint.setVisible(False)

        brush = QBrush(QColor(Qt.black))
        self._startPoint.setBrush(brush)
        self._endPoint.setBrush(brush)

        pen = QPen(brush, 2.0)
        self.setPen(pen)

    def showEndpoint(self, show):
        self._endPoint.setVisible(show)

    def setEndpoint(self, pos):
        self._p1 = pos
        self._endPoint.setPos(pos)
        self._updatePath()

    def _updatePath(self):
        p0 = self._p0
        p1 = self._p1

        path = QPainterPath()
        path.moveTo(p0)
        dx = p1.x() - p0.x()
        x0 = p0.x() + 0.7 * dx
        x1 = p1.x() - 0.7 * dx
        path.cubicTo(QPointF(x0, p0.y()), QPointF(x1, p1.y()), p1)
        self.setPath(path)
开发者ID:sonictk,项目名称:PyNodeGraph,代码行数:41,代码来源:dragged_line_item.py

示例2: AxisScene

# 需要导入模块: from PyQt4.QtGui import QGraphicsEllipseItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsEllipseItem import setPos [as 别名]
class AxisScene(QGraphicsScene):
    def __init__(self, parent = None):
        super(AxisScene, self).__init__(parent)
        self.guidePen = QPen(QColor("blue"),1)
        self.dot = QGraphicsEllipseItem(-10, -10, 20, 20)
        self.dot.setPos(QPointF(0,0))
        self.dot.setPen(QPen(QColor("red"), 4))
        self.dot.setBrush(QColor("black"))
        self.lastPos = {}
        self.lastPos['x'] = 0
        self.lastPos['y'] = 0
        self.grid = False
        self.gridPen = QPen(QColor("blue"), 2)
        self.pathItem = QGraphicsPathItem()
        self.pathItem.setPen(QPen(QColor("red"), 1, Qt.DotLine))
        self.path = None
        self.xAxis = "Select Axis..."
        self.yAxis = self.xAxis
        self.addItem(self.dot)
    
    def setXAxisName(self, x):
        self.xAxis = "Axis " + str(x)
        self.invalidate()

    def setYAxisName(self, y):
        self.yAxis = "Axis " + str(y)
        self.invalidate()

    def pathToggled(self, toggled):
        if toggled:
            self.path = QPainterPath()
            self.path.moveTo(0,0)
            self.pathItem.setPath(self.path)
            self.addItem(self.pathItem)
        else:
            if self.path != None:
                self.removeItem(self.pathItem)
            self.path = None
        self.invalidate()

    def gridToggled(self, toggled):
        self.grid = toggled
        self.invalidate()

    def updateDotX(self, x):
        self.lastPos['x'] = x * (self.sceneRect().width() / 2)
        self.update(self.lastPos['x'], self.lastPos['y'])
    
    def updateDotY(self, y):
        self.lastPos['y'] = y * (self.sceneRect().height() / 2)
        self.update(self.lastPos['x'], self.lastPos['y'])
    
    def update(self, x, y):
        if self.path != None:
            self.path.lineTo(x, y)
            self.pathItem.setPath(self.path)
        self.dot.setPos(self.lastPos['x'], self.lastPos['y'])
        self.invalidate()
    
    def drawBackground(self, painter, rect):
        if self.grid:
            painter.setClipRect(rect)
            painter.setPen(self.gridPen)

    def drawForeground(self, painter, rect):
        painter.setClipRect(rect)
        painter.setPen(self.gridPen)
        r = self.sceneRect()
        if self.grid:
            painter.drawLine(r.center().x(), r.top(), r.center().x(), r.bottom())
            painter.drawLine(r.left(), r.center().y(), r.right(), r.center().y())
            painter.setPen(QPen(QColor("red"), 1))
            painter.drawText(QRectF(r.left(), r.center().y(), 80, 80), self.xAxis)
            painter.drawText(QRectF(r.center().x()+5, r.top(), 80, 80), self.yAxis)
        if self.path != None:
            painter.setPen(QPen(QColor("red"), 1))
            painter.drawLine(QPointF(self.lastPos['x'], r.top()), QPointF(self.lastPos['x'], r.bottom()))
            painter.drawLine(QPointF(r.left(), self.lastPos['y']), QPointF(r.right(), self.lastPos['y']))
开发者ID:gentunian,项目名称:njoy,代码行数:80,代码来源:axeswidgets.py


注:本文中的PyQt4.QtGui.QGraphicsEllipseItem.setPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。