Python PyQt5.QtWidgets 模块,QGraphicsLineItem() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用PyQt5.QtWidgets.QGraphicsLineItem()

项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, upper, lower):
        super().__init__()
        #self.upper = QtWidgets.QGraphicsSimpleTextItem(str(upper))
        #self.divider = QtWidgets.QGraphicsLineItem(0,0,10,0)
        #self.divider.rotate(-70)
        #self.divider.setPen(GuiTupletNumber.pen)
        self.lower = QtWidgets.QGraphicsSimpleTextItem(str(lower))

        #self.upper.setParentItem(self)
        #self.divider.setParentItem(self)
        self.lower.setParentItem(self)

        #self.upper.setPos(-1,-8)
        #self.divider.setPos(5,5)
        #self.lower.setPos(7,-5)

        self.lower.setPos(-1,-4)
        self.setScale(0.75)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, parentView):
        super().__init__()

        self.parentView = parentView
        self.totalHeight = 71

        self.staticPoints = None #Cached backend staticRepresentationList: TempoPoints and interpolated points list
        self.staticBlocks = None #Cached Block Data list
        self.staticMeta = None #Cached track meta data dict.

        self.staffLine = QtWidgets.QGraphicsLineItem(0,0,10,0) #x1, y1, x2, y2
        self.staffLine.setParentItem(self)
        self.staffLine.setPos(0,0)

        self.timeLine = TimeLine(self) #registers its own callbacks
        self.timeLine.setParentItem(self)

        api.getCallbacksDatabase().updateTempoTrackBlocks.append(self.updateBlocks)
        api.getCallbacksDatabase().updateTempoTrack.append(self.createGraphicItemsFromData)
        api.getCallbacksDatabase().updateTempoTrackMeta.append(self.updateMetaData)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def updateGraphBlockTrack(self, staticRepresentationList):
        """Handles and visualizes block boundaries"""
        #{"type" : "GraphBlock", "id":id(block), "name":block.name, "duration":block.duration, "position":tickCounter}

        self.blockListCache = staticRepresentationList #sorted list
        self.blockdictCache = {} #reset

        for tbh in self.transparentBlockHandles:
            tbh.setParentItem(None)
            tbh.scene().removeWhenIdle(tbh)
        self.transparentBlockHandles = [] #reset

        #removeInstancesFromScene(CCGraphTransparentBlock) #this removes ALL blocks in all tracks from the scene. don't.
        for dictExportItem in staticRepresentationList:
            guiBlock = CCGraphTransparentBlock(parent = self, staticExportItem = dictExportItem, x = 0, y = -28, w = dictExportItem["duration"] / constantsAndConfigs.ticksToPixelRatio, h = 2*28)
            guiBlock.setParentItem(self)
            guiBlock.setPos(dictExportItem["position"] / constantsAndConfigs.ticksToPixelRatio,0)
            self.blockdictCache[dictExportItem["id"]] = guiBlock
            self.transparentBlockHandles.append(guiBlock)

        #Use the last item of the loop above to draw length of the boundary lines.
        maximumPixels = (dictExportItem["duration"] + dictExportItem["position"]) / constantsAndConfigs.ticksToPixelRatio
        upperLine = QtWidgets.QGraphicsLineItem(0,-28,maximumPixels,-28) #x1, y1, x2, y2
        #upperLine.setPen(QtGui.QColor("red"))
        upperLine.setParentItem(self)
        self.other.append(upperLine)
        lowerLine = QtWidgets.QGraphicsLineItem(0,28,maximumPixels,28) #x1, y1, x2, y2
        #lowerLine.setPen(QtGui.QColor("green"))
        lowerLine.setParentItem(self)
        self.other.append(lowerLine)
        upperLine.setOpacity(0.3)
        lowerLine.setOpacity(0.3)
        upperLine.setPos(0,0)
        lowerLine.setPos(0,0)
        #for self.stretchXCoordinates
        self.upperLine = upperLine
        self.lowerLine = lowerLine

        self.setRect(0,-28,maximumPixels,2*28)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def createStaffLines(self, lengthInPixel = 0):
        """By default creates 5 stafflines. But it can be 10;
        5 extra below the origin-staff.
        This is NOT a double-system like a piano but just a staff
        with more lines that happens to have the range of e.g.
        treble + bass clef."""

        def createLine(yOffset):
            line = QtWidgets.QGraphicsLineItem(QtCore.QLineF(0, 0, lengthInPixel, 0))
            line.setParentItem(self)
            line.setPen(cosmeticPen)
            self.staffLines.append(line)
            line.setPos(0, yOffset*constantsAndConfigs.stafflineGap)
            line.setZValue(-5) #This is the z value within GuiTrack

        for l in self.staffLines:
            self.parentScore.removeWhenIdle(l)
        self.staffLines = []
        lengthInPixel += 25 #a bonus that gives the hint that you can write after the last object.

        for i in range(-2, 3): #the normal 5 line system. We have a lower and upper range/position. The middle line is at position 0
            createLine(i)

        if self.staticExportItem["double"]: #add more stuffs below (user-perspective. positive Qt values)
            for i in range(4, 9): #i is now 3. Make a gap:
                createLine(i)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def createBarlines(self, barlinesTickList):
        """and measure numbers"""
        for bl in self.barLines:
            self.parentScore.removeWhenIdle(bl)
        self.barLines = []

        if self.staticExportItem["double"]:
            h = 10 * constantsAndConfigs.stafflineGap
        else:
            h = 4 * constantsAndConfigs.stafflineGap

        #if barlinesTickList[0] == 0: #happens when there is a metrical instruction at tick 0.
        #    del barlinesTickList[0]

        last = None
        offset = 0
        for barnumber, barlineTick in enumerate(barlinesTickList):
            if barlineTick == last:
                #print ("warning. Double barline at", barlineTick)
                offset += 1
                continue #don't draw the double barline
            last = barlineTick
            line = QtWidgets.QGraphicsLineItem(QtCore.QLineF(0, 0, 0, h))
            line.setParentItem(self)
            self.barLines.append(line)
            line.setPos(barlineTick / constantsAndConfigs.ticksToPixelRatio, -2*constantsAndConfigs.stafflineGap)

            number = QtWidgets.QGraphicsSimpleTextItem(str(barnumber+1-offset))
            number.setScale(0.75)
            number.setParentItem(line)
            number.setPos(-2, -3*constantsAndConfigs.stafflineGap) #-2 on X for a little fine tuning.
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, parent, positionInSeconds):
            self.__class__.instances.append(self)
            m, s = divmod(positionInSeconds, 60)
            text = "{}:{} min".format(str(int(m)).zfill(2), str(int(s)).zfill(2))
            super().__init__(text)

            marker = QtWidgets.QGraphicsLineItem(0, 0, 0, -10) #vertical marker to connect to the conductor line
            marker.setParentItem(self)