本文整理汇总了Python中PySide.QtGui.QPainter.drawLine方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.drawLine方法的具体用法?Python QPainter.drawLine怎么用?Python QPainter.drawLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.drawLine方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, pe):
# make an arrow polygon right in the middle
painter = QPainter(self)
painter.setPen(Qt.NoPen)
# draw the background transparent rect
painter.save()
painter.setOpacity(self.BACKGROUND_OPACITY)
# get the rectangle coordinates it should extend over the whole width with only a portion at the center
painter.setBrush(Qt.black)
empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
rect_top = empty_space_percent / 2 * self.height()
rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
painter.drawRect(0, rect_top, self.width(), rect_height)
painter.restore()
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen()
pen.setWidth(self.ARROW_LINE_WIDTH)
pen.setCapStyle(Qt.RoundCap)
if self._mouse_inside:
pen.setColor(self._hover_color)
else:
pen.setColor(self._normal_color)
# get the arrow coords
painter.setPen(pen)
self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
if self._direction == self.LEFT:
h_shift = self._arrow_width
elif self._direction == self.RIGHT:
h_shift = - self._arrow_width
v_shift = self._arrow_height / 2
top_point = self_center + QPointF(h_shift, - v_shift)
bottom_point = self_center + QPointF(h_shift, v_shift)
painter.drawLine(top_point, self_center)
painter.drawLine(self_center, bottom_point)
示例2: paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paint(self, canvas, is_secondary_color=False, additional_flag=False):
pen = QPen()
pen.setWidth(self.data_singleton.pen_size)
pen.setStyle(Qt.SolidLine)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
if is_secondary_color:
pen.setBrush(self.data_singleton.secondary_color)
else:
pen.setBrush(self.data_singleton.primary_color)
painter = QPainter(canvas.image)
painter.setPen(pen)
if self._start_point != self._end_point:
painter.drawLine(self._start_point, self._end_point)
if self._start_point == self._end_point:
painter.drawPoint(self._start_point)
painter.end()
canvas.edited = True
canvas.update()
示例3: __paintMargin
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def __paintMargin(self, event):
""" Paints the right margin as postPainting step. """
rect = event.rect()
font = self.editor.codeEdit.currentCharFormat().font()
fm = QFontMetricsF(font)
pos = self.marginPos
offset = self.editor.codeEdit.contentOffset().x() + \
self.editor.codeEdit.document().documentMargin()
x80 = round(fm.width(' ') * pos) + offset
p = QPainter(self.editor.codeEdit.viewport())
p.setPen(self.pen)
p.drawLine(x80, rect.top(), x80, rect.bottom())
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, event):
""" Paints the widget """
if self.enabled is False:
return
Panel.paintEvent(self, event)
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
for vb in self.editor.codeEdit.visible_blocks:
line = vb.row
# paint marker for line
marker = self.getIndicatorForLine(line)
if marker is None:
continue
# use the normal pen to draw the fold indicator
drawLines = False
pen = self.normal_pen
if marker.hover is True:
pen = self.highlight_pen
drawLines = True
painter.setPen(pen)
# get the text to draw
txt = '-'
if marker.folded is True:
drawLines = False
txt = '+'
offset = 4
h = self.size_hint.height()
fm = QFontMetricsF(self.editor.codeEdit.font())
hoffset = (fm.height() - h) / 2.0
r = QRect(vb.rect.x(), vb.rect.y() + hoffset, self.size_hint.width(), self.size_hint.height())
painter.setFont(self.font)
painter.drawText(r, Qt.AlignVCenter | Qt.AlignHCenter, txt)
w = self.size_hint.width() - 2 * offset
h = self.size_hint.width() - 2 * offset
hoffset = (fm.height() - h) / 2.0
r.setX(vb.rect.x() + offset)
r.setY(vb.rect.y() + hoffset)
r.setWidth(w)
r.setHeight(h)
painter.drawRect(r)
if drawLines is True:
top = (vb.rect.x() + self.size_hint.width() / 2.0,
vb.rect.y() + hoffset + offset * 2)
delta = ((marker.end - marker.start) * vb.height) # - (vb.rect.height() / 2.0)
bottom = (top[0], top[1] + delta)
painter.drawLine(top[0], top[1], bottom[0], bottom[1])
painter.drawLine(bottom[0], bottom[1], bottom[0] + self.size_hint.width() / 2.0, bottom[1])
return
示例5: draw_uvs
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def draw_uvs(self):
self.img = QPixmap(QSize(self.w, self.h))
pen = QPen()
pen.setWidth(int(self.pen_w.text()))
pen.setBrush(QBrush(Qt.white))
pen.setColor(QColor('white'))
painter = QPainter()
painter.begin(self.img)
painter.setPen(pen)
coords = self.get_coords()
for face in coords:
for n in xrange(len(face) - 1):
print face[n][0], face[n][1], face[n + 1][0], face[n + 1][1]
painter.drawLine(face[n][0], face[n][1], face[n + 1][0], face[n + 1][1])
painter.end()
self.view.scene().addPixmap(self.img)
示例6: drawPreview
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def drawPreview(self, endPoint_x, endPoint_y):
painter = QPainter(self.imagePreview)
painter.setPen(QPen(
self.myPenColor,
self.myPenWidth,
QtCore.Qt.SolidLine,
QtCore.Qt.RoundCap,
QtCore.Qt.RoundJoin))
painter.setClipping(True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setOpacity(0.5)
if self.tools['circle']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
x2 = endPoint_x
y2 = endPoint_y
painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))
if self.tools['line']:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
if self.tools['rect']:
painter.drawRect(
self.firstPoint_x, self.firstPoint_y,
endPoint_x - self.firstPoint_x,
endPoint_y - self.firstPoint_y)
if self.tools['roundRect']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
if x1 > endPoint_x and y1 > endPoint_y:
painter.drawRoundedRect(
endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
else:
painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)
self.update()
示例7: createPixmapIcon
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def createPixmapIcon(self):
self.markerIcon = QPixmap(MARKER_WIDTH, MARKER_HEIGHT)
self.markerIcon.fill(Qt.transparent)
painter = QPainter(self.markerIcon)
p1 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1)
p2 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1 - MARKER_PIN_LEN)
pen = QPen(Qt.black)
pen.setWidth(2)
pen.setCosmetic(True)
painter.setPen(pen)
painter.drawLine(p1, p2)
ellipse = QRect(0, 0, MARKER_WIDTH - 1, MARKER_HEIGHT - 1)
pen.setWidth(1)
painter.setPen(pen)
color = QColor(Qt.green)
color.setAlpha(127)
brush = QBrush(color)
painter.setBrush(brush)
painter.drawEllipse(ellipse)
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, pe):
painter = QPainter(self)
painter.save()
background = QColor(55, 55, 55)
brush = QBrush(background)
painter.setOpacity(self._opacity)
painter.setBrush(brush)
painter.setPen(Qt.NoPen)
painter.drawRect(self.rect())
painter.restore()
# draw a bottom border
painter.setPen(Qt.black)
painter.drawLine(0, self.height(), self.width(), self.height())
# now the text
pen = QPen(Qt.white)
pen.setWidth(16)
painter.setPen(pen)
painter.setFont(QFont("Trebuchet MS", 16, QFont.Bold))
text_rect = QRect(self.rect())
text_rect.adjust(self._margin, self._margin, self._margin, self._margin)
painter.drawText(text_rect, Qt.AlignLeft, self._message_str)
示例9: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, ev):
if not self._osx:
return
size = self.size()
height = size.height()-1
width = size.width()-1
painter = QPainter(self)
painter.setPen(QColor(165, 165, 165, 255))
painter.drawLine(QPoint(0, 0), QPoint(0, height))
painter.drawLine(QPoint(0, height), QPoint(width, height))
painter.drawLine(QPoint(width, height), QPoint(width, 0))
for index in range(self._buttonCount):
xCoord = (index + 1) * 21 - 1
painter.drawLine(QPoint(xCoord, 0), QPoint(xCoord, height))
示例10: draw
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def draw(self, endPoint_x, endPoint_y):
painter = QPainter(self.image)
painter.setPen(QPen(
self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine,
QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
painter.setClipping(True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setCompositionMode(QPainter.CompositionMode())
if self.tools['circle']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
x2 = endPoint_x
y2 = endPoint_y
painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))
if self.tools['eraser']:
painter.setPen(QPen(QtCore.Qt.white, 10, QtCore.Qt.SolidLine))
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
self.firstPoint_x = endPoint_x
self.firstPoint_y = endPoint_y
if self.tools['pen']:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
self.firstPoint_x = endPoint_x
self.firstPoint_y = endPoint_y
if self.tools['line'] and self.flag:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
if self.tools['rect']:
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
painter.drawRect(self.firstPoint_x, self.firstPoint_y, dx, dy)
if self.tools['roundRect']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
if x1 > endPoint_x and y1 > endPoint_y:
painter.drawRoundedRect(
endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
else:
painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)
self.modified = True
self.update()
示例11: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
self.img = QPixmap()
if self.isChecked():
painter.setBrush(self.color1)
painter.drawRoundedRect(QRect(-1, -1, 31, 31), 7, 7)
painter.drawPixmap(QRect(-2, -5, 35, 40), self.img.fromImage(self.check))
else:
pen = QPen()
pen.setWidth(2)
painter.setPen(pen)
# hand draw rect
painter.drawLine(QPoint(0, 0), QPoint(30, 0))
painter.drawLine(QPoint(30, 0), QPoint(30, 30))
painter.drawLine(QPoint(0, 0), QPoint(0, 30))
painter.drawLine(QPoint(0, 30), QPoint(30, 30))
painter.end()
示例12: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
def paintEvent(self, event):
super().paintEvent(event)
painter = QPainter(self)
# Рисование цифр в ячейки таблицы
for i in range(self.matrix_size):
for j in range(self.matrix_size):
# Если текущая ячейка относится к дефолтной судоку
if self.def_num_matrix[i][j]:
painter.save()
# painter.setPen()
painter.setBrush(Qt.yellow)
x = i * self.cell_size
y = j * self.cell_size
w, h = self.cell_size, self.cell_size
painter.drawRect(x, y, w, h)
painter.restore()
# TODO: Закомментировано
# Если индекс ячейки под курсором валидный
if 0 <= self.x_highlight_cell < self.matrix_size and 0 <= self.y_highlight_cell < self.matrix_size:
# # Выделение всего столбца и строки пересекающих ячейку под курсором
# painter.save()
# painter.setBrush(Qt.lightGray)
#
# # Выделение строки
# for i in range(self.matrix_size):
# painter.drawRect(i * self.cell_size,
# self.y_highlight_cell * self.cell_size,
# self.cell_size,
# self.cell_size)
#
# # Выделение столбца
# for j in range(self.matrix_size):
# painter.drawRect(self.x_highlight_cell * self.cell_size,
# j * self.cell_size,
# self.cell_size,
# self.cell_size)
#
# painter.restore()
x, y = self.x_highlight_cell, self.y_highlight_cell
# Не подсвечиваем дефолтную ячейку
if not self.def_num_matrix[x][y]:
# Выделение ячейки под курсором
painter.save()
painter.setBrush(Qt.darkYellow)
painter.drawRect(x * self.cell_size,
y * self.cell_size,
self.cell_size,
self.cell_size)
painter.restore()
# Рисование цифр в ячейки таблицы
for i in range(self.matrix_size):
for j in range(self.matrix_size):
num = self.matrix[i][j]
if not num:
continue
num = str(num)
# Алгоритм изменения размера текста взят из http://stackoverflow.com/a/2204501
# Для текущего пришлось немного адаптировать
factor = (self.cell_size / 2) / painter.fontMetrics().width(num)
if factor < 1 or factor > 1.25:
f = painter.font()
point_size = f.pointSizeF() * factor
if point_size > 0:
f.setPointSizeF(point_size)
painter.setFont(f)
x = i * self.cell_size
y = j * self.cell_size
w, h = self.cell_size, self.cell_size
painter.drawText(x, y, w, h, Qt.AlignCenter, num)
# Рисование сетки таблицы
y1, y2 = 0, 0
factor = min(self.width(), self.height()) / self.default_size
size = self.default_pen_size_1
size2 = self.default_pen_size_2
if factor < 1 or factor > 1.25:
size *= factor
if size < self.min_default_pen_size_2:
size = self.min_default_pen_size_2
painter.save()
for i in range(self.matrix_size + 1):
painter.setPen(QPen(Qt.black, size2 if i % 3 == 0 and i and i < self.matrix_size else size))
painter.drawLine(0, y1, self.cell_size * self.matrix_size, y2)
y1 += self.cell_size
y2 += self.cell_size
#.........这里部分代码省略.........
示例13: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawLine [as 别名]
#.........这里部分代码省略.........
self.__drawTriangle(painter, x, y)
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRect(x + 1, y + 1, w - 1, h - 1)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRect(x, y, w - 1, h - 1)
# draw a Maya style
if self._rolloutStyle == 4:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
painter.setRenderHint(QPainter.Antialiasing, False)
self.__drawTriangle(painter, x, y)
# draw the borders - top
headerHeight = 20
headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)
# Highlight
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(headerRect)
painter.fillRect(headerRect, QColor(255, 255, 255, 18))
# Shadow
pen.setColor(self.palette().color(QPalette.Dark))
painter.setPen(pen)
painter.drawRect(headerRectShadow)
if not self.isCollapsed():
# draw the lover border
pen = QPen(self.palette().color(QPalette.Dark))
pen.setWidthF(0.8)
painter.setPen(pen)
offSet = headerHeight + 3
bodyRect = QRect(x, y + offSet, w, h - offSet)
bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
painter.drawRect(bodyRect)
pen.setColor(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(bodyRectShadow)
# draw a boxed style
elif self._rolloutStyle == 1:
if self.isCollapsed():
arect = QRect(x + 1, y + 9, w - 1, 4)
brect = QRect(x, y + 8, w - 1, 4)
text = '+'
else:
arect = QRect(x + 1, y + 9, w - 1, h - 9)
brect = QRect(x, y + 8, w - 1, h - 9)
text = '-'
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRect(arect)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRect(brect)
painter.setRenderHint(painter.Antialiasing, False)
painter.setBrush(self.palette().color(QPalette.Window).darker(120))
painter.drawRect(x + 10, y + 1, w - 20, 16)
painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())
if self.dragDropMode():
rect = self.dragDropRect()
# draw the lines
l = rect.left()
r = rect.right()
cy = rect.center().y()
for y in (cy - 3, cy, cy + 3):
painter.drawLine(l, y, r, y)
painter.end()