What is the best way to do this?
-
Hi, I want to create an interface that allows users to draw whatever they want but those infographics are composed of segments of lines. For example, if you want to draw a square then it will consist of 4 different lines. It is apparent that the lines should not disappear when the paintevent is triggered. Currently, I am using a vector array to store the start and end QPoint of a line. Is there a better and sophisticated way of doing the job?
-
Hi and welcome to devnet,
An other possible way is to use a QPainterPath. Or a collection of QLine.
-
Thank you for your reply. I've decided to use QPainterPath to achieve this. But, I am wondering how to set the initial point for the path as I want my starting point to be the position at which the mouse is pressed.
-
@Christina123 Use mousePressEvent, it provides the cursor position as parameter https://doc.qt.io/qt-5/qwidget.html#mousePressEvent