[Qgis-developer] [Plugin] Catch click mouse events

Tim Sutton tim at linfiniti.com
Sun Dec 28 16:13:57 EST 2008


Hi

On Sun, 2008-12-28 at 16:32 +0100, Olivier Tournaire wrote:
> Hi all,
> 
> I am currently trying to write a plugin for QGis. I just need a simple
> thing: be able to catch click events. So, I just added in my plugin
> this piece of code:
> 
> // plugin.hpp
> // ...
> QgsMapToolEmitPoint* m_toolEmitPoint;
> // ...
> private slots:
>    // ...
>    void canvas_clicked(QgsPoint &point, Qt::MouseButton button);
> 
> // plugin.cpp
> // in the constructor
> m_toolEmitPoint = new QgsMapToolEmitPoint(m_mapCanvas);
> QObject::connect( (QgsMapToolEmitPoint*)m_toolEmitPoint ,
> SIGNAL(canvasClicked()) , this ,
> SLOT(canvas_clicked(QgsPoint&,Qt::MouseButton)) );
> // I also tried this version, but it does not work better:
> QObject::connect( (QgsMapToolEmitPoint*)m_toolEmitPoint ,
> SIGNAL(canvasClicked(QgsPoint&,Qt::MouseButton)) , this ,
> SLOT(canvas_clicked(QgsPoint&,Qt::MouseButton)) );
> 



When connecting signals and slots, you should use methods with the same
signature e.g.:

connect( mpMapTool, SIGNAL( mouseClicked( QgsPoint ) ), this,
SLOT( mouseC    licked( QgsPoint ) ) );

Take a look at the coordinatecapture plugin in qgis src for an easy to
follow example:

src/plugins/coordinate_capture/coordinatecapture.cpp

Regards



-- 
Tim Sutton - QGIS Project Steering Committee Member (Release  Manager)
==============================================
Visit http://linfiniti.com to find out about:
 * QGIS programming services
 * Mapserver and PostGIS based hosting plans
 * FOSS Consulting & Support Services
Skype: timlinux Irc: timlinux on #qgis at freenode.net
==============================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/qgis-developer/attachments/20081228/23c01619/attachment.bin


More information about the Qgis-developer mailing list