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

Jacky Volpes jacky.volpes at oslandia.com
Mon Feb 20 06:10:07 PST 2023


Hi Joseph,

Like you, rubber bands and drawing/paint stuff are quite obscure to me 
and I need to dig into it when I want something specific...
I don't have a direct answer, but you could look into existing code 
doing similar things: the plugins "beePen" and "Bezier Editing" 
available in QGIS are "freehand" drawing tools.
They might use some of these functions.

Regards,

-- 
Jacky Volpes

Ingénieur SIG - Oslandia


beePen: https://github.com/mauroalberti/beePen
Bezier Editing: https://github.com/tmizu23/BezierEditing



Le 19/02/2023 à 21:59, Joseph Burkhart via QGIS-Developer a écrit :
> 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
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230220/21622be3/attachment.htm>


More information about the QGIS-Developer mailing list