Class: QgsMapTip¶
- class qgis.gui.QgsMapTip¶
Bases:
PyQt5.QtWidgets.QWidget
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 aQgsWebView
, 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
QgsMapTip() Default constructor
Methods
Clear the current maptip if it exists
Returns the html that would be displayed in a maptip for a given layer.
Show a maptip at a given point on the map canvas
Returns the html that would be displayed in a maptip for a given layer.
- actionEvent(self, a0: QActionEvent | None)¶
- changeEvent(self, a0: QEvent | None)¶
- childEvent(self, a0: QChildEvent | None)¶
- clear(self, mpMapCanvas: QgsMapCanvas | None = None, msDelay: int = 0)¶
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)
- closeEvent(self, a0: QCloseEvent | None)¶
- connectNotify(self, signal: QMetaMethod)¶
- contextMenuEvent(self, a0: QContextMenuEvent | None)¶
- create(self, window: PyQt5.sip.voidptr = None, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- customEvent(self, a0: QEvent | None)¶
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, signal: QMetaMethod)¶
- dragEnterEvent(self, a0: QDragEnterEvent | None)¶
- dragLeaveEvent(self, a0: QDragLeaveEvent | None)¶
- dragMoveEvent(self, a0: QDragMoveEvent | None)¶
- dropEvent(self, a0: QDropEvent | None)¶
- enterEvent(self, a0: QEvent | None)¶
- event(self, a0: QEvent | None) bool ¶
- focusInEvent(self, a0: QFocusEvent | None)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, next: bool) bool ¶
- focusOutEvent(self, a0: QFocusEvent | None)¶
- focusPreviousChild(self) bool ¶
- hideEvent(self, a0: QHideEvent | None)¶
- initPainter(self, painter: QPainter | None)¶
- inputMethodEvent(self, a0: QInputMethodEvent | None)¶
- isSignalConnected(self, signal: QMetaMethod) bool ¶
- keyPressEvent(self, a0: QKeyEvent | None)¶
- keyReleaseEvent(self, a0: QKeyEvent | None)¶
- leaveEvent(self, a0: QEvent | None)¶
- metric(self, a0: QPaintDevice.PaintDeviceMetric) int ¶
- mouseDoubleClickEvent(self, a0: QMouseEvent | None)¶
- mouseMoveEvent(self, a0: QMouseEvent | None)¶
- mousePressEvent(self, a0: QMouseEvent | None)¶
- mouseReleaseEvent(self, a0: QMouseEvent | None)¶
- moveEvent(self, a0: QMoveEvent | None)¶
- nativeEvent(self, eventType: QByteArray | bytes | bytearray, message: PyQt5.sip.voidptr | None)¶
- paintEvent(self, a0: QPaintEvent | None)¶
- rasterMapTipPreviewText(layer: QgsMapLayer | None, mapCanvas: QgsMapCanvas | None, mapTemplate: str | None) str ¶
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
- receivers(self, signal: PYQT_SIGNAL) int ¶
- resizeEvent(self, a0: QResizeEvent | None)¶
- sender(self) QObject | None ¶
- senderSignalIndex(self) int ¶
- showEvent(self, a0: QShowEvent | None)¶
- showMapTip(self, thepLayer: QgsMapLayer | None, mapPosition: QgsPointXY, pixelPosition: QPoint, mpMapCanvas: QgsMapCanvas | None)¶
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
- tabletEvent(self, a0: QTabletEvent | None)¶
- timerEvent(self, a0: QTimerEvent | None)¶
- updateMicroFocus(self)¶
- vectorMapTipPreviewText(layer: QgsMapLayer | None, mapCanvas: QgsMapCanvas | None, mapTemplate: str | None, displayExpression: str | None) str ¶
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
- wheelEvent(self, a0: QWheelEvent | None)¶