So i have found a way to get an approximation of the bounding box. First you have to know the scale of the map, that the annotations are for and set them. setSymbologyReferenceScale
After that you use following code to get the approximation.
from qgis import core # creating memory vector layer for the visualation of the bounding box Prj = QgsProject().instance() lyr = QgsVectorLayer('Polygon?crs=epsg:25832','bounding_box',"memory") # change the epsg to your coordinate system Prj.addMapLayers([lyr]) # get all rendered items in the current canvas rendered_annot_list = iface.mapCanvas().renderedItemResults().renderedItems() # list of all annotation layer, length should be one for this code anno_layer_list= [x for x in iface.mapCanvas().layers() if isinstance(x, QgsAnnotationLayer)] if len(anno_layer_list) != 1: raise ValueError("There has to be only one ") # get a list of all items in the annotation layer annot_layer = anno_layer_list[0] list_annot_layer = annot_layer.items() # write all the annotation in a list that are visible in the current canvas annot_list = [] for ren_annot in rendered_annot_list: annot_list.append(list_annot_layer[ren_annot.itemId()]) # loop over all the annotations in the current canvas and get their bounding box for anno in annot_list: map_setting = core.QgsMapSettings() render_context = core.QgsRenderContext.fromMapSettings(map_setting) b_box = anno.boundingBox(render_context) print(b_box) # visualize the bounding box feature = QgsFeature() feature.setGeometry(QgsGeometry.fromRect(b_box)) lyr.startEditing() lyr.addFeature(feature) lyr.commitChanges(True)
After that you get the bounding box for the scale you set up beforehand. If you visualize it, it will look something like this:
As you see the bounding box is not perfect, but it is the best approximation i have found until now.