本文整理汇总了Python中PyQt4.QtGui.QPainter方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QPainter方法的具体用法?Python QtGui.QPainter怎么用?Python QtGui.QPainter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui
的用法示例。
在下文中一共展示了QtGui.QPainter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getHighlightedObject
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def getHighlightedObject(self, qp):
# These variables we want to fill
self.highlightObjs = []
self.highlightObjLabel = None
# Without labels we cannot do so
if not self.annotation:
return
# If available set the selected objects
highlightObjIds = self.selObjs
# If not available but the polygon is empty or closed, its the mouse object
if not highlightObjIds and (self.drawPoly.isEmpty() or self.drawPolyClosed) and self.mouseObj>=0 and not self.mouseOutsideImage:
highlightObjIds = [self.mouseObj]
# Get the actual object that is highlighted
if highlightObjIds:
self.highlightObjs = [ self.annotation.objects[i] for i in highlightObjIds ]
# Set the highlight object label if appropriate
if self.config.highlight:
self.highlightObjLabel = self.config.highlightLabelSelection
elif len(highlightObjIds) == 1 and self.config.correctionMode:
self.highlightObjLabel = self.annotation.objects[highlightObjIds[-1]].label
# Draw the image in the given QPainter qp
示例2: getHighlightedObject
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def getHighlightedObject(self, qp):
# This variable we want to fill
self.highlightObj = None
# Without labels we cannot do so
if not self.annotation:
return
# If available its the selected object
highlightObjId = -1
# If not available but the polygon is empty or closed, its the mouse object
if highlightObjId < 0 and not self.mouseOutsideImage:
highlightObjId = self.mouseObj
# Get the actual object that is highlighted
if highlightObjId >= 0:
self.highlightObj = self.annotation.objects[highlightObjId]
self.highlightObjLabel = self.annotation.objects[highlightObjId].label
# Draw the image in the given QPainter qp
示例3: drawDisp
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def drawDisp( self , qp ):
if not self.dispOverlay:
return
# Save QPainter settings to stack
qp.save()
# Define transparency
qp.setOpacity(self.transp)
# Draw the overlay image
qp.drawImage(QtCore.QRect( self.xoff, self.yoff, self.w, self.h ),self.dispOverlay)
# Restore settings
qp.restore()
return self.dispOverlay
#############################
## Mouse/keyboard events
#############################
# Mouse moved
# Need to save the mouse position
# Need to drag a polygon point
# Need to update the mouse selected object
示例4: drawDisp
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def drawDisp( self , qp ):
if not self.dispOverlay:
return
# Save QPainter settings to stack
qp.save()
# Define transparency
qp.setOpacity(self.transp)
# Draw the overlay image
qp.drawImage(QtCore.QRect( self.xoff, self.yoff, self.w, self.h ),self.dispOverlay)
# Restore settings
qp.restore()
return self.dispOverlay
#############################
## Mouse/keyboard events
#############################
# Mouse moved
# Need to save the mouse position
# Need to drag a polygon point
# Need to update the mouse selected object
示例5: registerCmap
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def registerCmap(self):
""" Add matplotlib cmaps to the GradientEditors context menu"""
self.gradientEditorItem.menu.addSeparator()
savedLength = self.gradientEditorItem.length
self.gradientEditorItem.length = 100
for name in self.mplColorMaps:
px = QPixmap(100, 15)
p = QPainter(px)
self.gradientEditorItem.restoreState(self.mplColorMaps[name])
grad = self.gradientEditorItem.getGradient()
brush = QBrush(grad)
p.fillRect(QtCore.QRect(0, 0, 100, 15), brush)
p.end()
label = QLabel()
label.setPixmap(px)
label.setContentsMargins(1, 1, 1, 1)
act =QWidgetAction(self.gradientEditorItem)
act.setDefaultWidget(label)
act.triggered.connect(self.cmapClicked)
act.name = name
self.gradientEditorItem.menu.addAction(act)
self.gradientEditorItem.length = savedLength
示例6: generatePicture
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def generatePicture(self):
## pre-computing a QPicture object allows paint() to run much more quickly,
## rather than re-drawing the shapes every time.
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen(color='w', width=0.4)) # 0.4 means w*2
# w = (self.data[1][0] - self.data[0][0]) / 3.
w = 0.2
for (t, open, close, min, max) in self.data:
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
if open > close:
p.setBrush(pg.mkBrush('g'))
else:
p.setBrush(pg.mkBrush('r'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
p.end()
示例7: mouseMoveEvent
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def mouseMoveEvent(self, e):
if e.buttons() == QtCore.Qt.LeftButton:
mimeData = QtCore.QMimeData()
mimeData.setText('%d,%d' % (e.x(), e.y()))
# show the ghost image while dragging
pixmap = QtGui.QPixmap.grabWidget(self)
painter = QtGui.QPainter(pixmap)
painter.fillRect(pixmap.rect(), QtGui.QColor(0, 0, 0, 127))
painter.end()
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(pixmap)
drag.setHotSpot(e.pos())
drag.exec_(QtCore.Qt.MoveAction)
示例8: generatePicture
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def generatePicture(self):
## pre-computing a QPicture object allows paint() to run much more quickly,
## rather than re-drawing the shapes every time.
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen(color='r', width=0.4)) # 0.4 means w*2
# w = (self.data[1][0] - self.data[0][0]) / 3.
w = 0.2
for (t, open, close, min, max) in self.data:
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
if open > close:
p.setBrush(pg.mkBrush('g'))
else:
p.setBrush(pg.mkBrush('r'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
p.end()
示例9: paintEvent
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.setRenderHints(QtGui.QPainter.Antialiasing)
painter.fillRect(QtCore.QRectF(50, 50, 200, 200), QtGui.QBrush(QtGui.QColor(QtGui.QColor(110, 110, 110))))
painter.fillRect(QtCore.QRectF(50, 50, 200, 200), QtGui.QBrush(QtCore.Qt.CrossPattern))
painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.lightGray), 2, QtCore.Qt.SolidLine))
path = QtGui.QPainterPath()
path.moveTo(50, 250)
path.cubicTo(self.points[0][0], self.points[0][1], self.points[1][0], self.points[1][1], 250, 50)
painter.drawPath(path)
painter.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.Qt.darkCyan)))
painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.lightGray), 1))
#for x, y in pts:
painter.drawEllipse(QtCore.QRectF(self.points[0][0] - 4, self.points[0][1] - 4, 8, 8))
painter.drawEllipse(QtCore.QRectF(self.points[1][0] - 4, self.points[1][1] - 4, 8, 8))
painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.white), 1))
label1 = "("+ str((self.points[0][0] - 50)/2) + "," + str(100 - ((self.points[0][1] -50)/2)) + ")"
painter.drawText(self.points[0][0] -25, self.points[0][1] + 18, QtCore.QString(label1))
label2 = "("+ str((self.points[1][0] - 50)/2) + "," + str(100 - ((self.points[1][1] -50)/2)) + ")"
painter.drawText(self.points[1][0] -25, self.points[1][1] + 18, QtCore.QString(label2))
示例10: paintEvent
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def paintEvent(self, event):
# Create a QPainter that can perform draw actions within a widget or image
qp = QtGui.QPainter()
# Begin drawing in the application widget
qp.begin(self)
# Update scale
self.updateScale(qp)
# Determine the object ID to highlight
self.getHighlightedObject(qp)
# Draw the image first
self.drawImage(qp)
# Draw the labels on top
overlay = self.drawLabels(qp)
# Draw the user drawn polygon
self.drawDrawPoly(qp)
self.drawDrawRect(qp)
# Draw the label name next to the mouse
self.drawLabelAtMouse(qp)
# Draw the zoom
# self.drawZoom(qp, overlay)
self.drawZoom(qp,None)
# Thats all drawing
qp.end()
# Forward the paint event
QtGui.QMainWindow.paintEvent(self,event)
# Update the scaling
示例11: getPolygon
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def getPolygon(self, obj):
poly = QtGui.QPolygonF()
for pt in obj.polygon:
point = QtCore.QPointF(pt.x,pt.y)
poly.append( point )
return poly
# Draw the labels in the given QPainter qp
# optionally provide a list of labels to ignore
示例12: ptClosesPoly
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def ptClosesPoly(self):
if self.drawPoly.isEmpty():
return False
if self.mousePosScaled is None:
return False
closestPt = self.getClosestPoint( self.drawPoly, self.mousePosScaled )
return closestPt==(0,0)
# Draw a point using the given QPainter qp
# If its the first point in a polygon its drawn in green
# if not in red
# Also the radius might be increased
示例13: paintEvent
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def paintEvent(self, event):
qp = QtGui.QPainter()
qp.begin(self)
self.draw_memory(event, qp)
qp.end()
示例14: get_icon
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def get_icon(icon, size=24):
"""get svg icon from icon resources folder as a pixel map
"""
img = get_icon_path("{}.svg".format(icon))
svg_renderer = QtSvg.QSvgRenderer(img)
image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32)
# Set the ARGB to 0 to prevent rendering artifacts
image.fill(0x00000000)
svg_renderer.render(QtGui.QPainter(image))
pixmap = QtGui.QPixmap.fromImage(image)
return pixmap
示例15: drawModeBox
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QPainter [as 别名]
def drawModeBox(self, qp, xy, col, txt):
#qp = QtGui.QPainter()
qp.save()
qp.translate(xy)
qp.setBrush(col.dark())
qp.setPen(QPen(col, 0.5, Qt.SolidLine))
qp.setFont(QFont('Monospace', 14, QFont.Monospace))
rh = 11
rw = 20
r=QRectF(-rw,-rh, 2*rw, 2*rh)
qp.drawRect(r)
qp.drawText(r, Qt.AlignCenter, txt)
qp.restore()