Python PyQt5.QtGui.QPainter.Antialiasing() Examples
The following are 30
code examples of PyQt5.QtGui.QPainter.Antialiasing().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui.QPainter
, or try the search function
.
Example #1
Source File: waiting_animation.py From malss with MIT License | 6 votes |
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 200))) painter.setPen(QPen(Qt.NoPen)) if self.lists is not None: path = os.path.abspath(os.path.dirname(__file__)) + '/static/' path += self.lists[self.list_index] + '.png' self.list_index += 1 if self.list_index >= len(self.lists): self.list_index = 0 image = QImage(path) rect_image = image.rect() rect_painter = event.rect() dx = (rect_painter.width() - rect_image.width()) / 2.0 dy = (rect_painter.height() - rect_image.height()) / 2.0 painter.drawImage(dx, dy, image) painter.end()
Example #2
Source File: PercentProgressBar.py From PyQt with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, event): super(PercentProgressBar, self).paintEvent(event) width = self.width() height = self.height() side = min(width, height) painter = QPainter(self) # 反锯齿 painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing) # 坐标中心为中间点 painter.translate(width / 2, height / 2) # 按照100x100缩放 painter.scale(side / 100.0, side / 100.0) # 绘制中心园 self._drawCircle(painter, 50) # 绘制圆弧 self._drawArc(painter, 50 - self.BorderWidth / 2) # 绘制文字 self._drawText(painter, 50)
Example #3
Source File: MetroCircleProgress.py From PyQt with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, event): super(MetroCircleProgress, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillRect(self.rect(), self.BackgroundColor) painter.setPen(Qt.NoPen) for item, _ in self._items: painter.save() color = self.Color.toRgb() color.setAlphaF(item.opacity) painter.setBrush(color) # 5<= radius <=10 radius = qBound(self.Radius, self.Radius / 200 * self.height(), 2 * self.Radius) diameter = 2 * radius painter.drawRoundedRect( QRectF( item.x / 100 * self.width() - diameter, (self.height() - radius) / 2, diameter, diameter ), radius, radius) painter.restore()
Example #4
Source File: RoundProgressBar.py From PyQt with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, event): super(CircleProgressBar, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.translate(self.width() / 2, self.height() / 2) side = min(self.width(), self.height()) painter.scale(side / 100.0, side / 100.0) painter.rotate(self.angle) painter.save() painter.setPen(Qt.NoPen) color = self.Color.toRgb() for i in range(11): color.setAlphaF(1.0 * i / 10) painter.setBrush(color) painter.drawEllipse(30, -10, 20, 20) painter.rotate(36) painter.restore() self.angle += self.Delta if self.Clockwise else -self.Delta self.angle %= 360
Example #5
Source File: SplineChart.py From PyQt with GNU General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 300) # 抗锯齿 self.setRenderHint(QPainter.Antialiasing) # 图表 chart = QChart() self.setChart(chart) # 设置标题 chart.setTitle('Simple splinechart example') # 添加Series self.getSeries(chart) # 创建默认xy轴 chart.createDefaultAxes() chart.legend().setVisible(False)
Example #6
Source File: CLoadingBar.py From CustomWidgets with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, _): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # 背景 painter.fillRect(self.rect(), Qt.transparent) # 进度块 ratio = (self.value() - self.minimum()) / \ (self.maximum() - self.minimum()) width = self.rect().width() * ratio if self.isError: color = QColor(self._failedColor or CLoadingBar.FailedColor) else: color = QColor(self._color or CLoadingBar.Color) color.setAlpha(self._alpha) painter.setBrush(color) painter.setPen(Qt.NoPen) painter.drawRoundedRect(QRectF(0, 0, width, self.height()), 2, 2)
Example #7
Source File: LineStack.py From PyQt with GNU General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(ChartView, self).__init__(*args, **kwargs) self.resize(800, 600) self.setRenderHint(QPainter.Antialiasing) # 抗锯齿 # 自定义x轴label self.category = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] self.initChart() # 提示widget self.toolTipWidget = GraphicsProxyWidget(self._chart) # line self.lineItem = QGraphicsLineItem(self._chart) pen = QPen(Qt.gray) pen.setWidth(1) self.lineItem.setPen(pen) self.lineItem.setZValue(998) self.lineItem.hide() # 一些固定计算,减少mouseMoveEvent中的计算量 # 获取x和y轴的最小最大值 axisX, axisY = self._chart.axisX(), self._chart.axisY() self.min_x, self.max_x = axisX.min(), axisX.max() self.min_y, self.max_y = axisY.min(), axisY.max()
Example #8
Source File: ChartView.py From PyQt with GNU General Public License v3.0 | 6 votes |
def __analysis(self, datas): ''' analysis json data :param datas: json data ''' # 标题 self.__setTitle(datas.get("title", None)) # 抗锯齿 if (datas.get("antialiasing", False) or False): self.setRenderHint(QPainter.Antialiasing) # 主题 self._chart.setTheme(datas.get("theme", 0) or 0) # 动画 self.__setAnimation(datas.get("animation", None)) # 背景设置 self.__setBackground(datas.get("background", None)) # 边距设置 self.__setMargins(datas.get("margins", None)) # 设置图例 self.__setLegend(datas.get("legend", None)) # 设置series self.__setSeries(datas.get("series", None)) # 自定义的x轴 self.__setAxisX(datas.get("axisx", None)) # 自定义的y轴
Example #9
Source File: botonCircular.py From PyQt5 with MIT License | 6 votes |
def paintEvent(self, event): ancho, altura = self.width(), self.height() icono = self.icono.scaled(ancho, altura, Qt.KeepAspectRatio, Qt.SmoothTransformation) pintor = QPainter() pintor.begin(self) pintor.setRenderHint(QPainter.Antialiasing, True) pintor.setPen(Qt.NoPen) pintor.drawPixmap(0, 0, icono, 0, 0, 0, 0) pintor.setPen(Qt.white) pintor.drawText(event.rect(), Qt.AlignCenter, self.etiqueta) pintor.setPen(Qt.NoPen) pintor.setBrush(self.opacidad) pintor.drawEllipse(0, 0, ancho, altura) pintor.end() self.setMask(icono.mask())
Example #10
Source File: ScatterChart.py From PyQt with GNU General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 300) # 抗锯齿 self.setRenderHint(QPainter.Antialiasing) # 生成模拟数据 self.m_dataTable = self.generateRandomData(3, 10, 7) # 图表 chart = QChart() self.setChart(chart) # 设置标题 chart.setTitle('Scatter chart') # 添加Series self.getSeries(chart) # 创建默认xy轴 chart.createDefaultAxes() chart.legend().setVisible(False)
Example #11
Source File: loadf2.py From CNNArt with Apache License 2.0 | 6 votes |
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillRect(event.rect(), QBrush(QColor(255,255, 255, 127))) painter.setPen(QPen(QtCore.Qt.NoPen)) for i in range(6): if (self.counter / 5) % 6 == i: painter.setBrush(QBrush(QColor(127 + (self.counter % 5) * 32, 0, 0))) else: painter.setBrush(QBrush(QColor(0, 0, 0))) painter.drawEllipse( self.width() / 2 + 30 * math.cos(2 * math.pi * i / 6.0) - 10, self.height() / 2 + 30 * math.sin(2 * math.pi * i / 6.0) - 10, 20, 20) painter.end()
Example #12
Source File: invites.py From IDArling with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, event): # noqa: N802 """We override the painting event to draw the invite ourselves.""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) rect = QRect(self.rect()) # Draw the border painter.setBrush(QBrush(QColor(122, 122, 122))) painter.setPen(Qt.NoPen) painter.drawRect(rect) rect.setX(rect.x() + 1) rect.setY(rect.y() + 1) rect.setWidth(rect.width() - 1) rect.setHeight(rect.height() - 1) # Draw the background painter.setBrush(QBrush(QColor(255, 255, 225))) painter.setPen(Qt.NoPen) painter.drawRect(rect)
Example #13
Source File: view.py From gridsync with GNU General Public License v3.0 | 6 votes |
def paintEvent(self, event): if not self.model().rowCount(): self.show_drop_label() painter = QPainter(self.viewport()) painter.setRenderHint(QPainter.Antialiasing) pen = QPen(QColor(128, 128, 128), 5) pen.setDashPattern([1, 2.91]) painter.setPen(pen) geometry = self.geometry() painter.drawRect( geometry.x(), geometry.y() + self.dropzone_top_margin, geometry.width() - 24, geometry.height() - 24, ) super().paintEvent(event)
Example #14
Source File: paint.py From 15-minute-apps with MIT License | 6 votes |
def text_mousePressEvent(self, e): if e.button() == Qt.LeftButton and self.current_pos is None: self.current_pos = e.pos() self.current_text = "" self.timer_event = self.text_timerEvent elif e.button() == Qt.LeftButton: self.timer_cleanup() # Draw the text to the image p = QPainter(self.pixmap()) p.setRenderHints(QPainter.Antialiasing) font = build_font(self.config) p.setFont(font) pen = QPen(self.primary_color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) p.setPen(pen) p.drawText(self.current_pos, self.current_text) self.update() self.reset_mode() elif e.button() == Qt.RightButton and self.current_pos: self.reset_mode()
Example #15
Source File: VerificationCode.py From PyQt with GNU General Public License v3.0 | 5 votes |
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 背景白色 painter.fillRect(event.rect(), QBrush(Qt.white)) # 绘制边缘虚线框 painter.setPen(Qt.DashLine) painter.setBrush(Qt.NoBrush) painter.drawRect(self.rect()) # 随机画条线 for _ in range(3): painter.setPen(QPen(QTCOLORLIST[qrand() % 5], 1, Qt.SolidLine)) painter.setBrush(Qt.NoBrush) painter.drawLine(QPoint(0, qrand() % self.height()), QPoint(self.width(), qrand() % self.height())) painter.drawLine(QPoint(qrand() % self.width(), 0), QPoint(qrand() % self.width(), self.height())) # 绘制噪点 painter.setPen(Qt.DotLine) painter.setBrush(Qt.NoBrush) for _ in range(self.width()): # 绘制噪点 painter.drawPoint(QPointF(qrand() % self.width(), qrand() % self.height())) # super(WidgetCode, self).paintEvent(event) # 绘制文字 # 绘制跳动文字 metrics = QFontMetrics(self.font()) x = (self.width() - metrics.width(self.text())) / 2 y = (self.height() + metrics.ascent() - metrics.descent()) / 2 for i, ch in enumerate(self.text()): index = (self.step + i) % 16 painter.setPen(TCOLORLIST[qrand() % 6]) painter.drawText(x, y - ((SINETABLE[index] * metrics.height()) / 400), ch) x += metrics.width(ch)
Example #16
Source File: CircleImage.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, antialiasing=True, **kwargs): super(Label, self).__init__(*args, **kwargs) self.Antialiasing = antialiasing self.setMaximumSize(200, 200) self.setMinimumSize(200, 200) self.radius = 100 #####################核心实现######################### self.target = QPixmap(self.size()) # 大小和控件一样 self.target.fill(Qt.transparent) # 填充背景为透明 p = QPixmap("Data/Images/head.jpg").scaled( # 加载图片并缩放和控件一样大 200, 200, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) painter = QPainter(self.target) if self.Antialiasing: # 抗锯齿 painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # painter.setPen(# 测试圆圈 # QPen(Qt.red, 5, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) path = QPainterPath() path.addRoundedRect( 0, 0, self.width(), self.height(), self.radius, self.radius) # **** 切割为圆形 ****# painter.setClipPath(path) # painter.drawPath(path) # 测试圆圈 painter.drawPixmap(0, 0, p) self.setPixmap(self.target) #####################核心实现#########################
Example #17
Source File: NinePatch.py From PyQt with GNU General Public License v3.0 | 5 votes |
def paintEvent(self, event): super(Label, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.SmoothPixmapTransform) try: self.image.SetImageSize(self.width(), self.height()) self.image.Draw(painter, 0, 0) except Exception as e: print(e)
Example #18
Source File: BubbleTips.py From PyQt with GNU General Public License v3.0 | 5 votes |
def paintEvent(self, event): super(BubbleLabel, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 抗锯齿 rectPath = QPainterPath() # 圆角矩形 triPath = QPainterPath() # 底部三角形 height = self.height() - 8 # 往上偏移8 rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5) x = self.width() / 5 * 4 triPath.moveTo(x, height) # 移动到底部横线4/5处 # 画三角形 triPath.lineTo(x + 6, height + 8) triPath.lineTo(x + 12, height) rectPath.addPath(triPath) # 添加三角形到之前的矩形上 # 边框画笔 painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # 背景画刷 painter.setBrush(self.BackgroundColor) # 绘制形状 painter.drawPath(rectPath) # 三角形底边绘制一条线保证颜色与背景一样 painter.setPen(QPen(self.BackgroundColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(x, height, x + 12, height)
Example #19
Source File: ToolTip2.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ChartView, self).__init__(*args, **kwargs) self.resize(800, 600) self.setRenderHint(QPainter.Antialiasing) # 抗锯齿 self.initChart() self.toolTipWidget = GraphicsProxyWidget(self._chart) # line self.lineItem = QGraphicsLineItem(self._chart) self.lineItem.setZValue(998) self.lineItem.hide() # 一些固定计算,减少mouseMoveEvent中的计算量 # 获取x和y轴的最小最大值 axisX, axisY = self._chart.axisX(), self._chart.axisY() self.min_x, self.max_x = axisX.min(), axisX.max() self.min_y, self.max_y = axisY.min(), axisY.max() # 坐标系中左上角顶点 self.point_top = self._chart.mapToPosition( QPointF(self.min_x, self.max_y)) # 坐标原点坐标 self.point_bottom = self._chart.mapToPosition( QPointF(self.min_x, self.min_y)) self.step_x = (self.max_x - self.min_x) / (axisX.tickCount() - 1) # self.step_y = (self.max_y - self.min_y) / (axisY.tickCount() - 1)
Example #20
Source File: ImageSlipped.py From PyQt with GNU General Public License v3.0 | 5 votes |
def paintEvent(self, event): super(SlippedImgWidget, self).paintEvent(event) # 绘制图形 painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 左上角偏移5个像素画背景图片 painter.drawPixmap( -5 + self._offsets[0], -5 + self._offsets[1], self.bgPixmap) # 右下角偏移5个像素画前景图片 painter.drawPixmap( self.width() - self.pePixmap.width() + 5 - self._offsets[2], self.height() - self.pePixmap.height() + 5 - self._offsets[3], self.pePixmap )
Example #21
Source File: ScreenShotPage.py From PyQt with GNU General Public License v3.0 | 5 votes |
def onScreenShot1(self): # 截图方式1 page = self.webView.page() oldSize = self.webView.size() self.webView.resize(page.contentsSize().toSize()) def doScreenShot(): rect = self.webView.contentsRect() size = rect.size() image = QImage(size, QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) painter = QPainter() painter.begin(image) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.TextAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) self.webView.render(painter) painter.end() self.webView.resize(oldSize) # 添加到左侧list中 item = QListWidgetItem(self.widgetRight) image = QPixmap.fromImage(image) item.setIcon(QIcon(image)) item.setData(Qt.UserRole + 1, image) # 先等一下再截图吧 QTimer.singleShot(2000, doScreenShot)
Example #22
Source File: ScreenShotPage.py From PyQt with GNU General Public License v3.0 | 5 votes |
def onScreenShot1(self): # 截图方式1 page = self.webView.page() frame = page.mainFrame() size = frame.contentsSize() image = QImage(size, QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) painter = QPainter() painter.begin(image) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.TextAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # 记录旧大小 oldSize = page.viewportSize() # *****重点就是这里****** page.setViewportSize(size) frame.render(painter) painter.end() # 截图完成后需要还原,否则界面不响应鼠标等 page.setViewportSize(oldSize) # 添加到左侧list中 item = QListWidgetItem(self.widgetRight) image = QPixmap.fromImage(image) item.setIcon(QIcon(image)) item.setData(Qt.UserRole + 1, image)
Example #23
Source File: ocrwidget.py From lector with GNU General Public License v2.0 | 5 votes |
def __init__(self, lang, areaType, statusBar): QGraphicsView.__init__(self) self.ocrscene = OcrScene(self, lang, areaType) self.setScene(self.ocrscene) self.setCacheMode(QGraphicsView.CacheBackground) self.setRenderHint(QPainter.Antialiasing) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QGraphicsView.AnchorViewCenter) self.setMinimumSize(200, 200) self.language = lang self.statusBar = statusBar self.areaType = areaType self.resizingArea = None self.resizingAreaPos = None self.resizingAreaRect = None self.resizingEdge = None self.resizingStartingPos = None self.areaBorder = float() self.areaTextSize = float() self.setCursor(Qt.CrossCursor) self.scene().isModified = False self.bResizing = False self.filename = None Image.init()
Example #24
Source File: SelectableGraphicView.py From urh with GNU General Public License v3.0 | 5 votes |
def __init__(self, parent=None): super().__init__(parent) self.setResizeAnchor(QGraphicsView.NoAnchor) self.setTransformationAnchor(QGraphicsView.NoAnchor) self.setRenderHints(QPainter.Antialiasing) self.scene_manager = None # type: SceneManager self.mouse_press_pos = None # type: QPoint self.mouse_pos = None # type: QPoint self.grab_start = None # type: QPoint self.move_y_with_drag = False self.xmove = 0 self.separation_area_moving = False self.shift_mode = False # Shift Key currently pressed? self.select_all_action = QAction(self.tr("Select all"), self) self.select_all_action.setShortcut(QKeySequence.SelectAll) self.select_all_action.triggered.connect(self.select_all) self.select_all_action.setShortcutContext(Qt.WidgetWithChildrenShortcut) self.select_all_action.setIcon(QIcon.fromTheme("edit-select-all")) self.addAction(self.select_all_action)
Example #25
Source File: CircleLine.py From PyQt with GNU General Public License v3.0 | 5 votes |
def paintEvent(self, event): super(CircleLineWindow, self).paintEvent(event) if not self._canDraw: return painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.SmoothPixmapTransform) self.draw(painter)
Example #26
Source File: ToolTip.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ChartView, self).__init__(*args, **kwargs) self.resize(800, 600) self.setRenderHint(QPainter.Antialiasing) # 抗锯齿 self.initChart() self.toolTipWidget = GraphicsProxyWidget(self._chart) # line self.lineItem = QGraphicsLineItem(self._chart) self.lineItem.setZValue(998) self.lineItem.hide() # 一些固定计算,减少mouseMoveEvent中的计算量 # 获取x和y轴的最小最大值 axisX, axisY = self._chart.axisX(), self._chart.axisY() self.min_x, self.max_x = axisX.min(), axisX.max() self.min_y, self.max_y = axisY.min(), axisY.max() # 坐标系中左上角顶点 self.point_top = self._chart.mapToPosition( QPointF(self.min_x, self.max_y)) # 坐标原点坐标 self.point_bottom = self._chart.mapToPosition( QPointF(self.min_x, self.min_y)) self.step_x = (self.max_x - self.min_x) / (axisX.tickCount() - 1) # self.step_y = (self.max_y - self.min_y) / (axisY.tickCount() - 1)
Example #27
Source File: HorizontalBarChart.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 300) # 抗锯齿 self.setRenderHint(QPainter.Antialiasing) # 图表 chart = QChart() self.setChart(chart) # 设置标题 chart.setTitle('Simple horizontal barchart example') # 开启动画效果 chart.setAnimationOptions(QChart.SeriesAnimations) # 添加Series series = self.getSeries() chart.addSeries(series) # 分类 categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] # 分类x轴 axis = QBarCategoryAxis() axis.append(categories) # 创建默认轴线 chart.createDefaultAxes() # 替换默认y轴 chart.setAxisY(axis, series) # 显示图例 chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom)
Example #28
Source File: PercentBarChart.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 300) # 抗锯齿 self.setRenderHint(QPainter.Antialiasing) # 图表 chart = QChart() self.setChart(chart) # 设置标题 chart.setTitle('Simple percentbarchart example') # 开启动画效果 chart.setAnimationOptions(QChart.SeriesAnimations) # 添加Series series = self.getSeries() chart.addSeries(series) # 分类 categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] # 分类x轴 axis = QBarCategoryAxis() axis.append(categories) # 创建默认轴线 chart.createDefaultAxes() # 替换默认x轴 chart.setAxisX(axis, series) # 显示图例 chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom)
Example #29
Source File: PieChart.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 300) # 抗锯齿 self.setRenderHint(QPainter.Antialiasing) # 图表 chart = QChart() self.setChart(chart) # 设置标题 chart.setTitle('Simple piechart example') # 添加Series chart.addSeries(self.getSeries())
Example #30
Source File: pixmap.py From gridsync with GNU General Public License v3.0 | 5 votes |
def __init__(self, pixmap, text, size=0.5, corner=BottomRight): super().__init__() base_pixmap = QPixmap(pixmap) base_size = base_pixmap.size() base_max = min(base_size.height(), base_size.width()) if not base_max: # Because gridsync.gui.systray.animation.currentPixmap() returns # a blank pixmap when unpausing the animation for the first time. # Returning early to prevents QPainter from spewing warnings. self.swap(base_pixmap) return badge_max = base_max * size pen_width = badge_max * 0.05 rect = QRect( base_max * max(corner[0] - size, 0) + pen_width, base_max * max(corner[1] - size, 0) + pen_width, badge_max - pen_width, badge_max - pen_width, ) painter = QPainter(base_pixmap) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(QPen(Qt.red, pen_width)) painter.setBrush(QBrush(Qt.red)) painter.drawEllipse(rect) if text: font = painter.font() font.setPixelSize(badge_max - pen_width) painter.setFont(font) painter.setPen(Qt.white) painter.drawText(rect, Qt.AlignCenter, str(text)) painter.end() self.swap(base_pixmap)