本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsLineItem.setPen方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.setPen方法的具体用法?Python QGraphicsLineItem.setPen怎么用?Python QGraphicsLineItem.setPen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsLineItem
的用法示例。
在下文中一共展示了QGraphicsLineItem.setPen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_clearance_graph
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def add_clearance_graph(self):
print("-----------------------------------------")
horizontal_clearance = self.clearance_analysis.horizontal_clearance
x_init = self.graph_zero[0] + self.line_extend
y_init = self.graph_zero[1]
for i in range(len(horizontal_clearance)):
clearance_points = horizontal_clearance[i]
x = x_init + i * self.dimension_analysis.section_distance * self.length_multiplier
left = -self.dimension_analysis.domain_length
right = self.dimension_analysis.domain_length
if clearance_points[0]:
left = clearance_points[0]
if clearance_points[1]:
right = clearance_points[1]
clearance = right - left
y_top = y_init + left * self.height_multiplier
y_bottom = y_init + right * self.height_multiplier
pen_red = QPen()
red = Color.create_qcolor_from_rgb_tuple(Color.red)
pen_red.setColor(red)
pen_green = QPen()
green = Color.create_qcolor_from_rgb_tuple(Color.green)
pen_green.setColor(green)
line = QGraphicsLineItem(x, y_top, x, y_bottom)
if clearance < self.min_horizontal_clearance:
line.setPen(pen_red)
else:
line.setPen(pen_green)
self.addToGroup(line)
pass
示例2: add_dummy_line_for_margin
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def add_dummy_line_for_margin(self):
height = self.scene.height()
width = self.scene.width()
pen = QPen()
pen.setStyle(Qt.NoPen)
dummy_line_a= QGraphicsLineItem(0, height, 0, height + 100)
dummy_line_b = QGraphicsLineItem(width, 0, width + 100, 0)
dummy_line_a.setPen(pen)
dummy_line_b.setPen(pen)
self.scene.addItem(dummy_line_a)
self.scene.addItem(dummy_line_b)
示例3: create_axis
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def create_axis(self):
bounding_end = abs(self.dimension_analysis.bounding_rect[3])
bounding_start = abs(self.dimension_analysis.bounding_rect[2])
pen = QPen()
pen.setWidthF(0.5)
# horizontal line
self.graph_zero[0] = self.position[0] + self.margin - self.line_extend
self.graph_zero[1] = self.position[1] + bounding_start * self.height_multiplier + self.margin
self.graph_end[0] = self.graph_zero[0] + self.content_width + self.line_extend
self.graph_end[1] = self.graph_zero[1]
line_item_horizontal = QGraphicsLineItem(self.graph_zero[0], self.graph_zero[1], self.graph_end[0], self.graph_end[1])
line_item_horizontal.setPen(pen)
self.addToGroup(line_item_horizontal)
center = (self.graph_zero[0] + self.line_extend), self.graph_zero[1]
y_top = center[1] - (bounding_start*self.height_multiplier)
y_bottom = center[1]+(bounding_end*self.height_multiplier)
line_item_vertical = QGraphicsLineItem(center[0], y_top, center[0], y_bottom)
line_item_vertical.setPen(pen)
self.addToGroup(line_item_vertical)
pen_thin = QPen()
pen_thin.setWidthF(0.2)
start_graph = center[1] - 10
while start_graph > center[1] - bounding_start * self.height_multiplier:
line_item_horizontal = QGraphicsLineItem(self.graph_zero[0], start_graph, self.graph_end[0], start_graph)
line_item_horizontal.setPen(pen_thin)
line_item_horizontal.setZValue(-0.5)
self.addToGroup(line_item_horizontal)
start_graph -= 10
start_graph = center[1] + 10
while start_graph < center[1] + bounding_end * self.height_multiplier:
line_item_horizontal = QGraphicsLineItem(self.graph_zero[0], start_graph, self.graph_end[0], start_graph)
line_item_horizontal.setPen(pen_thin)
line_item_horizontal.setZValue(-0.5)
self.addToGroup(line_item_horizontal)
start_graph += 10
示例4: generateData
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def generateData(self, canvas, lines, params):
scene = QGraphicsScene()
scene.setSceneRect(canvas)
group = scene.createItemGroup([])
for line in lines:
clone = QGraphicsLineItem(line)
clone.setLine(line.line())
clone.setPen(line.pen())
scene.addItem(clone)
group.addToGroup(clone)
pixmaps = []
for i in xrange(params.count):
pixmaps.append(self.generateRandom(scene, group, canvas, params))
return pixmaps
示例5: __init__
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def __init__(self, origX, origY, perCell, n):
super(GridItem, self).__init__();
length = perCell*n/2;
pen = QPen(Qt.DashLine);
pen.setColor(QColor(230, 230, 230))
pen.setWidth(0);
x1, y1, x2, y2 = origX-length, origY-length, origX-length, origY+length
for i in range(1, n):
line = QGraphicsLineItem(x1, y1, x2, y2, self)
line.setPen(pen)
x1, y1, x2, y2 = x1+perCell, y1, x2+perCell, y2
x1, y1, x2, y2 = origX-length, origY-length, origX+length, origY-length
for i in range(1, n):
line = QGraphicsLineItem(x1, y1, x2, y2, self)
line.setPen(pen)
x1, y1, x2, y2 = x1, y1+perCell, x2, y2+perCell
示例6: createArrow
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def createArrow(self):
rad = self._RADIUS
pen = QPen()
pen.setWidth(3)
color = QColor(Qt.blue)
color.setAlphaF(0.25)
pen.setBrush(color)
if self._virtual_helix.isEvenParity():
arrow = QGraphicsLineItem(rad, rad, 2*rad, rad, self)
else:
arrow = QGraphicsLineItem(0, rad, rad, rad, self)
arrow.setTransformOriginPoint(rad, rad)
arrow.setZValue(400)
arrow.setPen(pen)
self.arrow = arrow
self.arrow.hide()
示例7: drawNewFence
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def drawNewFence(self, fps):
self.clearFencePoints()
prev_fp = None
for i in range(1, len(fps)):
if prev_fp is not None:
prev_x = prev_fp.lon
prev_y = -prev_fp.lat
mapped_x = fps[i].lon
mapped_y = -fps[i].lat
next_line = QGraphicsLineItem(prev_x, prev_y,
mapped_x, mapped_y, self.__fence_layer)
l_pen = QPen(QColor(0, 255, 0))
l_pen.setWidth(0.1)
next_line.setPen(l_pen)
self.__fence_layer.addToGroup(next_line)
prev_fp = fps[i]
示例8: moveTo
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def moveTo(self, pos):
# data coordinates
oldX, oldY = self.pos.x(), self.pos.y()
x, y = pos.x(), pos.y()
line = QGraphicsLineItem(oldX, oldY, x, y)
line.setPen(QPen(QBrush(Qt.white), self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.scene.addItem(line)
self._hasMoved = True
# update bounding Box
if not self.bb.isValid():
self.bb = QRect(QPoint(oldX, oldY), QSize(1, 1))
# grow bounding box
self.bb.setLeft(min(self.bb.left(), max(0, x - self.brushSize // 2 - 1)))
self.bb.setRight(max(self.bb.right(), min(self.sliceRect[0] - 1, x + self.brushSize // 2 + 1)))
self.bb.setTop(min(self.bb.top(), max(0, y - self.brushSize // 2 - 1)))
self.bb.setBottom(max(self.bb.bottom(), min(self.sliceRect[1] - 1, y + self.brushSize // 2 + 1)))
# update/move position
self.pos = pos
示例9: drawGrid
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def drawGrid(self):
black_notes = [2,4,6,9,11]
scale_bar = QGraphicsRectItem(0, 0, self.grid_width, self.note_height, self.piano)
scale_bar.setPos(self.piano_width, 0)
scale_bar.setBrush(QColor(100,100,100))
clearpen = QPen(QColor(0,0,0,0))
for i in range(self.end_octave - self.start_octave, self.start_octave - self.start_octave, -1):
for j in range(self.notes_in_octave, 0, -1):
scale_bar = QGraphicsRectItem(0, 0, self.grid_width, self.note_height, self.piano)
scale_bar.setPos(self.piano_width, self.note_height * j + self.octave_height * (i - 1))
scale_bar.setPen(clearpen)
if j not in black_notes:
scale_bar.setBrush(QColor(120,120,120))
else:
scale_bar.setBrush(QColor(100,100,100))
measure_pen = QPen(QColor(0, 0, 0, 120), 3)
half_measure_pen = QPen(QColor(0, 0, 0, 40), 2)
line_pen = QPen(QColor(0, 0, 0, 40))
for i in range(0, int(self.num_measures) + 1):
measure = QGraphicsLineItem(0, 0, 0, self.piano_height + self.header_height - measure_pen.width(), self.header)
measure.setPos(self.measure_width * i, 0.5 * measure_pen.width())
measure.setPen(measure_pen)
if i < self.num_measures:
number = QGraphicsSimpleTextItem('%d' % (i + 1), self.header)
number.setPos(self.measure_width * i + 5, 2)
number.setBrush(Qt.white)
for j in self.frange(0, self.time_sig[0]*self.grid_div/self.time_sig[1], 1.):
line = QGraphicsLineItem(0, 0, 0, self.piano_height, self.header)
line.setZValue(1.0)
line.setPos(self.measure_width * i + self.value_width * j, self.header_height)
if j == self.time_sig[0]*self.grid_div/self.time_sig[1] / 2.0:
line.setPen(half_measure_pen)
else:
line.setPen(line_pen)
示例10: drawWPLine
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def drawWPLine(self, wp1, wp2):
if wp1 is None or wp2 is None:
print("Error: Can't draw line for Null endpoint")
return
rad = self.__wp_diameter * 0.5
mapped_wp1_x = wp1.y - rad
mapped_wp1_y = -wp1.x
#tangential approach?
if (wp1.command == mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT
and wp1.param1 == 1.0):
l_rad = abs(self.__wp_loiter_radius)
if l_rad is not None:
dis = acs_math.gps_distance(wp1.x, wp1.y, wp2.x, wp2.y)
theta = math.degrees(math.atan(l_rad / dis))
#sign of self.__wp_loiter_radius indicates the direction of the
#loiter (negative is counter-clockwise, postive is clockwise)
#Also, the waypoint itself can override the default setting
#via param2
if ((wp1.param2 == 0 and self.__wp_loiter_radius > 0.0) or
wp1.param2 > 0.0):
theta = -theta
tan_dis = math.sqrt( dis * dis - l_rad * l_rad)
bearing = acs_math.gps_bearing(wp2.x, wp2.y, wp1.x, wp1.y)
(tan_wp_x, tan_wp_y) = acs_math.gps_newpos(wp2.x, wp2.y,
bearing - theta, tan_dis)
mapped_wp1_x = tan_wp_y - rad
mapped_wp1_y = -tan_wp_x
next_line = QGraphicsLineItem(mapped_wp1_x, mapped_wp1_y,
wp2.y - rad, -wp2.x, self.__mission_layer)
l_pen = QPen(QColor(255, 255, 255))
l_pen.setWidth(0.00002)
next_line.setPen(l_pen)
self.__mission_layer.addToGroup(next_line)
示例11: onMouseMove_draw
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def onMouseMove_draw(self, imageview, event):
self._navIntr.onMouseMove_default(imageview, event)
o = imageview.scene().data2scene.map(QPointF(imageview.oldX, imageview.oldY))
n = imageview.scene().data2scene.map(QPointF(imageview.x, imageview.y))
# Draw temporary line for the brush stroke so the user gets feedback before the data is really updated.
pen = QPen(
QBrush(self._brushingCtrl._brushingModel.drawColor),
self._brushingCtrl._brushingModel.brushSize,
Qt.SolidLine,
Qt.RoundCap,
Qt.RoundJoin,
)
line = QGraphicsLineItem(o.x(), o.y(), n.x(), n.y())
line.setPen(pen)
imageview.scene().addItem(line)
line.setParentItem(imageview.scene().dataRectItem)
self._lineItems.append(line)
self._brushingCtrl._brushingModel.moveTo(imageview.mousePos)
示例12: createArrows
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def createArrows(self):
rad = _RADIUS
pen1 = self._pen1
pen2 = self._pen2
pen1.setWidth(3)
pen2.setWidth(3)
pen1.setBrush(Qt.gray)
pen2.setBrush(Qt.lightGray)
if self._virtual_helix.isEvenParity():
arrow1 = QGraphicsLineItem(rad, rad, 2*rad, rad, self)
arrow2 = QGraphicsLineItem(0, rad, rad, rad, self)
else:
arrow1 = QGraphicsLineItem(0, rad, rad, rad, self)
arrow2 = QGraphicsLineItem(rad, rad, 2*rad, rad, self)
arrow1.setTransformOriginPoint(rad, rad)
arrow2.setTransformOriginPoint(rad, rad)
arrow1.setZValue(400)
arrow2.setZValue(400)
arrow1.setPen(pen1)
arrow2.setPen(pen2)
self.arrow1 = arrow1
self.arrow2 = arrow2
self.arrow1.hide()
self.arrow2.hide()
示例13: ParticipantItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
class ParticipantItem(QGraphicsItem):
def __init__(self, model_item: Participant, parent=None):
super().__init__(parent)
self.model_item = model_item
self.text = QGraphicsTextItem(self)
self.line = QGraphicsLineItem(self)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
self.refresh()
def update_position(self, x_pos=-1, y_pos=-1):
if x_pos == -1:
x_pos = self.x_pos()
if y_pos == -1:
y_pos = self.line.line().y2()
self.text.setPos(x_pos - (self.text.boundingRect().width() / 2), 0)
self.line.setLine(x_pos, 30, x_pos, y_pos)
def x_pos(self):
return self.line.line().x1()
def width(self):
return self.boundingRect().width()
def refresh(self):
self.text.setPlainText("?" if not self.model_item else self.model_item.shortname)
if hasattr(self.model_item, "simulate") and self.model_item.simulate:
font = QFont()
font.setBold(True)
self.text.setFont(font)
self.text.setDefaultTextColor(Qt.darkGreen)
self.line.setPen(QPen(Qt.darkGreen, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
else:
self.text.setFont(QFont())
self.text.setDefaultTextColor(constants.LINECOLOR)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
def boundingRect(self):
return self.childrenBoundingRect()
def paint(self, painter, option, widget):
pass
示例14: add_dummy_line
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
def add_dummy_line(self):
pen = QPen()
pen.setStyle(Qt.NoPen)
dummy_line = QGraphicsLineItem(0, 0, 0, 100)
dummy_line.setPen(pen)
self.scene.addItem(dummy_line)
示例15: CalendarDesklet
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsLineItem import setPen [as 别名]
class CalendarDesklet(Desklet):
def __init__(self):
super().__init__()
self.model = CalendarModel()
self.cursor_pos = None
self.cursor = QGraphicsRectItem(self.root)
self.header = QGraphicsSimpleTextItem(self.root)
self.weekdays = []
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for day in days:
self.weekdays.append(QGraphicsSimpleTextItem(day, self.root))
self.header_line = QGraphicsLineItem(self.root)
self.days = []
for _ in range(0, 6 * 7):
self.days.append(QGraphicsSimpleTextItem(self.root))
def next_month(self):
self.model.next_month()
self.layout()
def previous_month(self):
self.model.previous_month()
self.layout()
def set_rect(self, rect):
super().set_rect(rect)
self.layout()
def set_style(self, style):
super().set_style(style)
font = QFont(style.font)
font.setPixelSize(48)
self.header.setBrush(style.midcolor)
self.header.setFont(font)
font = QFont(style.font)
font.setPixelSize(32)
self.header_line.setPen(style.foreground_color)
self.cursor.setBrush(style.midcolor)
self.cursor.setPen(QPen(Qt.NoPen))
for widget in self.weekdays:
widget.setFont(font)
widget.setBrush(style.foreground_color)
for widget in self.days:
widget.setFont(font)
widget.setBrush(self.style.foreground_color)
self.layout()
def layout(self):
cell_width = (self.rect.width()) / 7.0
cell_height = (self.rect.height() - 64) / 7.0
x = self.rect.left()
y = self.rect.top()
fm = QFontMetrics(self.header.font())
rect = fm.boundingRect(self.header.text())
self.header.setPos(x + self.rect.width() / 2 - rect.width() / 2,
y)
y += fm.height()
for row, day in enumerate(self.weekdays):
fm = QFontMetrics(day.font())
rect = fm.boundingRect(day.text())
day.setPos(x + row * cell_width + cell_width / 2 - rect.width() / 2,
y)
y += fm.height()
self.header_line.setLine(x, y,
x + self.rect.width() - 3, y)
y += 8
for n, widget in enumerate(self.days):
col = n % 7
row = n // 7
rect = fm.boundingRect(widget.text())
widget.setPos(x + col * cell_width + cell_width / 2 - rect.width() / 2,
y + row * cell_height + cell_height / 2 - fm.height() / 2)
# if day.month != self.now.month:
# widget.setBrush(self.style.midcolor)
# else:
if self.cursor_pos is not None:
#.........这里部分代码省略.........