I have a shape drawn with QPainter, which I need to be able to update dynamically, from a single variable called 'width'. I have attached an image to hopefully show what I mean...
Basically the shape should have three parts. Taking the existing shape (in blue), I need to split it down the middle and add a horizontal section, who's length is determined by 'width' var. I would like this shape to be a fully enclosed outline, with no breaks or visible joins.
My problem is simply trying to figure out how to use arcs in QPainter. I'm not understanding the difference between 'arcMoveTo', and 'arcTo' and how to get these things to work for me.
Current code of the basic shape is here:
import sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *class Canvas(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setMouseTracking(True) def paintEvent(self, event): qp = QPainter(self) qp.setRenderHint(QPainter.Antialiasing, True) pen = QPen(Qt.black, 15) pen.setJoinStyle(Qt.MiterJoin) qp.setPen(pen) qp.setBrush(Qt.blue) p = QPainterPath(QPointF(0, 100)) p.arcTo(25, 25, 150, 150, 205, 309) p.lineTo(0, 100) qp.drawPath(p) def mouseMoveEvent(self, event): # show x and y pos on screen mp = event.pos() p = self.mapToGlobal(mp) p.setY(p.y()-60) p.setX(p.x()+10) QToolTip.showText(p, "x:{}\ny:{}".format(mp.x(), mp.y()))if __name__ == '__main__': import sys app = QApplication(sys.argv) window = Canvas() window.show() sys.exit(app.exec())
I would very much appreciate if someone could help out on this. I've been making a mess of this shape all night! ;)
Looking forward to any replies,
Cheers!Ekar