PDA

View Full Version : allow user to draw n sided polygons in an open window



bruceqtbeginner
7th June 2016, 20:06
Hello, I am a very inexperienced with Qt and qml and programming in general. Can someone explain the best method for implementing a feature that would allow a user to draw a polygon in a window? i want it to be able to draw one straight line from one node to another and then eventually close the polygon. Thank you

anda_skoa
8th June 2016, 19:10
Since you mentioned QML I assume we are talking about a QtQuick based UI.

The easiest way for a custom UI component that does that is to derive from QQuickPaintedItem and implement mousePressEvent() such that it stores the mouse positions in a vector or list and then use these values in paint() to draw the polyline using the given QPainter.

I would suggest to start with just drawing a fixed polyline to get to know how the QPainter API works inside the QQuickPaintedItem and how registering the item type as well as using it from QML works.

Cheers,
_