qpainter

How to draw a rectangle and adjust its shape by drag and drop in PyQt5

血红的双手。 提交于 2019-12-03 21:16:11
I'm trying to draw a rectangle on GUI created by PyQt5 by drag and drop. I managed to do that, but the rectangle is drawn when the mouse left key is released. What I want to do is like this link : When the mouse left button is pressed, start drawing the rectangle. While dragging, adjust the rectangle shape with the mouse movement. When the mouse left button is released, determine the rectangle shape. How can I implement this? Thanks in advance. Here's my code. # -*- coding: utf-8 -*- import sys from PyQt5 import QtWidgets, QtCore from PyQt5.QtGui import QPainter class MyWidget(QtWidgets

Qt - circles for collision detection

荒凉一梦 提交于 2019-12-03 18:12:03
问题 I've been working on a physics simulation with circles in Qt. Thus far the easiest way to define circles I found is to make a QRect object and then draw the ellipse with that rectangle as a "blueprint". Now I've just got the problem that it paints a circle but the hit box for the hit detection is still a square, which looks rather awkward. I've not been able to find a solution for it thus far and hope to find some help here. QRectF Ball::boundingRect() const { return QRect(0,0,20,20); } void

Stroking a path only inside/outside?

允我心安 提交于 2019-12-03 17:21:40
Given a QPainterPath how can I stroke the path only on the inside or outside edge of the path (or left- or right-side for non-closed paths)? QPainter::strokePath() centers the pen along the path and causes the same amount of ink to fall on both sides. For a visual example of the desired effect, see this graphic I made (for an SVG proposal, not feature): I don't mind if this is done through some hack like setting the path itself as a clipping region (for inside) or anti-clipping region (for outside). The goal here is to fill a rounded rectangle with a low-opacity fill and then stroke just

How to draw and fill a triangle with QPainter?

感情迁移 提交于 2019-12-03 14:40:02
This is what I tried, it gave me no output. Where am I going wrong? // Start point of bottom line qreal startPointX1 = 600.0; qreal startPointY1 = 600.0; // End point of bottom line qreal endPointX1 = 600.0; qreal endPointY1 = 1200.0; // Start point of top line qreal startPointX2 = 600.0; qreal startPointY2 = 600.0; // End point of top line qreal endPointX2 = 800.0; qreal endPointY2 = 1200.0; QPainterPath path; // Set pen to this point. path.moveTo (startPointX1, startPointY1); // Draw line from pen point to this point. path.lineTo (endPointX1, endPointY1); path.moveTo (endPointX1, endPointY1)

Make an animated wave with drawPolyline in PySide/PyQt

自作多情 提交于 2019-12-03 13:25:32
问题 I'm trying to animate a polyline (it have to act like a wave). I've tried this way: from PySide.QtCore import * from PySide.QtGui import * import sys, time class Test(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) def poly(self, pts): return QPolygonF(map(lambda p: QPointF(*p), pts)) def paintEvent(self, event): painter = QPainter(self) pts = [[80, 490], [180, 0], [280, 0], [430, 0], [580, 0], [680, 0], [780, 0]] for i in pts: while i[1] < 600: painter

How to disable multiple auto-redrawing at resizing widgets in PyQt?

笑着哭i 提交于 2019-12-03 08:38:34
I have a PyQt4 program with widgets whose content redraws very slowly (it's ok, because of my tasks). And when I trying to resize those widgets, program is trying to redraw a lot of times while mouse is not released. That's a lot of freezes. I want to disable that auto-redrawing and configure PyQt to redraw all widgets only when mouse is released (which means that redraw happens exactly one time per one resize). How to do that? Edit1. I'll see it quite simply, like this: you drag the line, and while you dragging, all widgets stand. When you release it, widgets redrawing. But I'm really not

Efficient off-screen rendering of QPainterPaths (OpenGL and non-OpenGL solution required)

て烟熏妆下的殇ゞ 提交于 2019-12-03 06:29:29
问题 In my application, I paint a street map using QPainter on a widget made by QPainterPaths that contain precalculated paths to be drawn the widget is currently a QWidget , not a QGLWidget , but this might change. I'm trying to move the painting off-screen and split it into chunked jobs I want to paint each chunk onto a QImage and finally draw all images onto the widget QPainterPaths are already chunked, so this is not the problem problem is, that drawing on QImages is about 5 times slower than

Make an animated wave with drawPolyline in PySide/PyQt

依然范特西╮ 提交于 2019-12-03 03:35:34
I'm trying to animate a polyline (it have to act like a wave). I've tried this way: from PySide.QtCore import * from PySide.QtGui import * import sys, time class Test(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) def poly(self, pts): return QPolygonF(map(lambda p: QPointF(*p), pts)) def paintEvent(self, event): painter = QPainter(self) pts = [[80, 490], [180, 0], [280, 0], [430, 0], [580, 0], [680, 0], [780, 0]] for i in pts: while i[1] < 600: painter.setPen(QPen(QColor(Qt.darkGreen), 3)) painter.drawPolyline(self.poly(pts)) painter.setBrush(QBrush(QColor

Efficient off-screen rendering of QPainterPaths (OpenGL and non-OpenGL solution required)

浪尽此生 提交于 2019-12-02 19:59:58
In my application, I paint a street map using QPainter on a widget made by QPainterPaths that contain precalculated paths to be drawn the widget is currently a QWidget , not a QGLWidget , but this might change. I'm trying to move the painting off-screen and split it into chunked jobs I want to paint each chunk onto a QImage and finally draw all images onto the widget QPainterPaths are already chunked, so this is not the problem problem is, that drawing on QImages is about 5 times slower than drawing on QWidget Some benchmark testing I've done time values are rounded averages over multiple runs

How to QPainter inside QLabel

陌路散爱 提交于 2019-12-02 14:41:19
问题 I can not understand how to make the QPainter() draw inside a QLabel, here is the code I told would have worked: import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import QPainter, QColor, QBrush class Labella(QLabel): def __init__(self, parent): super().__init__() lb = QLabel('text', parent) lb.setStyleSheet('QFrame {background-color:grey;}') lb.resize(200, 200) qp = QPainter(lb) qp.begin(lb); qp.setBrush(QColor(200, 0, 0)) qp.drawRect(0,0,20,20); qp.end(); def paintEvent(self, e): qp