Hi,

For a standalone Pyqgis App I needed such function, so here it is (implemented 
for a QgsMapTool) :

from PyQt4 import QtCore

from PyQt4.QtGui import QPixmap , QApplication

# QGIS bindings for mapping functions
from qgis.gui import QgsMapTool

import tempfile

try:
   _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
   _fromUtf8 = lambda s: s

class SnapshotTool(QgsMapTool):
    ''' Provide a tool copy map canvas to clipboard '''
    def __init__(self, parent):
        QgsMapTool.__init__(self, parent.canvas)
        self.mainwindow = parent
        self.canvas = parent.canvas
#-------------------------------------------------------------------------------
    ''' Overridden QgsMapTool Events '''
#-------------------------------------------------------------------------------
    def canvasPressEvent(self, event):
        ''' Get point and transform to map coordinates '''
        point = event.pos()
        self.transform = self.mainwindow.canvas.getCoordinateTransform()
        # returns a QgsPoint object in map coordinates
        qgsPoint = self.transform.toMapCoordinates(point.x(), point.y())

        self.copyPaste2Clipboard(point, qgsPoint)


    def canvasReleaseEvent(self, event):
        pass

    def copyPaste2Clipboard(self, point, qgsPoint):
        ''' Get canvas and copy to clipboard '''
        # debugging
        print "copyPaste2Clipboard()"
        pxmap = QPixmap.grabWidget(self.canvas)
        QApplication.clipboard().setPixmap(pxmap)


→  Sylvain PIERRE
         Chef de projet système d’information
         Direction des Systèmes d’Information
         Service Projets et Applications Numériques
       Conseil Départemental du Bas-Rhin

[cid:image001.jpg@01D25C34.CB1FA830]<http://www.bas-rhin.fr/>

         Hôtel du Département
         1 place du Quartier Blanc 67964 Strasbourg Cedex 9
         Tél : 03 88 76 68 88 - mobile :
         Mobile : 06 30 96 31 76
         Email : sylvain.pie...@bas-rhin.fr<mailto:sylvain.pie...@bas-rhin.fr>
         www.bas-rhin.fr<http://www.bas-rhin.fr>


De : Qgis-user [mailto:qgis-user-boun...@lists.osgeo.org] De la part de Larry 
Shaffer
Envoyé : mardi 20 décembre 2016 21:44
À : DelazJ
Cc : qgis-user@lists.osgeo.org
Objet : Re: [Qgis-user] Tool to copy the content of the map canvas to the 
clipboard

Hi,

On Tue, Dec 20, 2016 at 11:02 AM, DelazJ 
<del...@gmail.com<mailto:del...@gmail.com>> wrote:
Hi,
2016-12-20 18:23 GMT+01:00 Bo Victor Thomsen 
<bo.victor.thom...@gmail.com<mailto:bo.victor.thom...@gmail.com>>:
Hi List-members -

Is there in Qgis a function / button / menu-item / short-cut / plugin to make a 
simple bitmap copy of the current content of the map-canvas and save it to the 
clipboard ? My users need this to make a copy of the map and paste into MS-Word 
or other software.

While not part of the QGIS app, one could use this PyQGIS snippet to do so 
(tested quickly on macOS 10.11.6 under QGIS 2.14) from the PyQGIS console:

from PyQt4.QtGui import *
QApplication.clipboard().setImage(QImage(QPixmap.grabWidget(iface.mapCanvas())))

This avoids having to re-render the QGraphicsView (QgsMapCanvas) to a paint 
device, like an image. Code can be wrapped in a plugin, then have some key 
bindings applied (would need some more PyQt).

Larry Shaffer
Dakota Cartography
Black Hills, South Dakota

I really need the functionality for my users and I can't seem to find it. The 
closest I've come is the "save as png" menu-item in the project menu. But it's 
to cumbersome to use in this case.

Afaics, there's no "save as png" option but "save as image" in Project menu, 
option from which you can choose the image file format (bmp, jpg...). It's not 
on the clipboard but easier and more accessible than print composer.
Regards,
Harrissou


I'm familiar with the composer function. My users can't use this neither 
because it takes to long to activate (to many choices and to many buttons to 
click)

So I've decided to make a simple plugin to cover this functionality. But first 
I want to be very sure the function actually is missing ;-)

Regards
Bo Victor Thomsen
Municipality of Frederikssund, Denmark.
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org<mailto:Qgis-user@lists.osgeo.org>
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user


_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org<mailto:Qgis-user@lists.osgeo.org>
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to