[QGIS-Developer] PyQGIS: how to modify default behavior of QgsRubberBand

Joseph Burkhart joseph.burkhart1 at comcast.net
Sun Feb 19 12:59:33 PST 2023


Hello,

I'm working on a python plugin that provides a new map tool for drawing polygons and I'm hoping someone could give me some pointers. I'm very familiar with the pyqgis API when it comes to processing, less so (but learning) when it comes to gui.

I have created a new polygon drawing tool that behaves like the default one. What I want to do now is modify the drawing widget so that it behaves more like a brush tool, so the user can activate the tool, click on the map canvas and drag to leave a brush stroke, and when they release the mouse button the brush stroke is turned into a polygon.

My impression is that I need to create a subclass of QgsRubberBand and then re-implement that class's draw method, but honestly I can't figure out where to start with that reimplementation. I've read through the pyqt docs for QPainter, and through the pyqgis docs and source code for QgsRubberBand (links below); I still couldn't figure out what to do next.

Anyone have any recommendations?

Thanks very much,

Joseph Burkhart



QgsRubberBand:
https://qgis.org/pyqgis/3.28/gui/QgsRubberBand.html
https://github.com/qgis/QGIS/blob/master/src/gui/qgsrubberband.h https://github.com/qgis/QGIS/blob/master/src/gui/qgsrubberband.h, https://github.com/qgis/QGIS/blob/master/src/gui/qgsgeometryrubberband.cpp

QPainter:
https://doc.qt.io/qtforpython-5/PySide2/QtGui/QPainter.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230219/3e36017b/attachment.htm>


More information about the QGIS-Developer mailing list