Class: QgsMapTip¶
A maptip is a class to display a tip on a map canvas when a mouse is hovered over a feature.
Since QGIS 2.16 a maptip can show full html. QgsMapTip
is a
QgsWebView
, so you can load full HTML/JS/CSS in it.
The code found in the map tips tab is inserted in a inline-block div so the frame can be resized based on the content size.
If no element in the html has a width attribute, the frame will squeeze down to the widest word. To avoid this you can wrap your HTML in a div style=”width:300px” or similar.
JS can be included using the script tag as usual, while CSS files must be linked using link rel=”stylesheet” href=”URL.css” the html specs discourages link rel=”stylesheet” in the body, but all browsers allow it. see https://jakearchibald.com/2016/link-in-body
Class Hierarchy¶
Base classes¶
Methods
Clear the current maptip if it exists |
|
Show a maptip at a given point on the map canvas |
Static Methods
Returns the html that would be displayed in a maptip for a given layer. |
|
Returns the html that would be displayed in a maptip for a given layer. |
- class qgis.gui.QgsMapTip[source]¶
Bases:
QWidget
- __init__()
Default constructor
- clear(self, mpMapCanvas: QgsMapCanvas | None = None, msDelay: int = 0)[source]¶
Clear the current maptip if it exists
- Parameters:
mpMapCanvas (Optional[QgsMapCanvas] = None) – the canvas from which the tip should be cleared.
msDelay (int = 0) – optional time in ms to defer clearing the maptip (since QGIS 3.26)
- static rasterMapTipPreviewText(layer: QgsMapLayer | None, mapCanvas: QgsMapCanvas | None, mapTemplate: str | None) str [source]¶
Returns the html that would be displayed in a maptip for a given layer. The center pixel of the raster is used to evaluate the expressions.
Added in version 3.32.
- Parameters:
layer (Optional[QgsMapLayer])
mapCanvas (Optional[QgsMapCanvas])
mapTemplate (Optional[str])
- Return type:
str
- showMapTip(self, thepLayer: QgsMapLayer | None, mapPosition: QgsPointXY, pixelPosition: QPoint, mpMapCanvas: QgsMapCanvas | None)[source]¶
Show a maptip at a given point on the map canvas
- Parameters:
thepLayer (Optional[QgsMapLayer]) – a qgis vector map layer pointer that will be used to provide the attribute data for the map tip.
mapPosition (QgsPointXY) – a reference to the position of the cursor in map coordinatess.
pixelPosition (QPoint) – a reference to the position of the cursor in pixel coordinates.
mpMapCanvas (Optional[QgsMapCanvas]) – a map canvas on which the tip is drawn
- static vectorMapTipPreviewText(layer: QgsMapLayer | None, mapCanvas: QgsMapCanvas | None, mapTemplate: str | None, displayExpression: str | None) str [source]¶
Returns the html that would be displayed in a maptip for a given layer. If the layer has features, the first feature is used to evaluate the expressions.
Added in version 3.32.
- Parameters:
layer (Optional[QgsMapLayer])
mapCanvas (Optional[QgsMapCanvas])
mapTemplate (Optional[str])
displayExpression (Optional[str])
- Return type:
str