#pragma once
#include <memory>
#include <qgspointxy.h>
#include <qtextdocument.h>
#include <qgsmapcanvas.h>
#include <qgstextannotation.h>
#include <qgsmapcanvasannotationitem.h>
class biaopai
{
public:
biaopai(QgsMapCanvas* _canvas)
{
m_annotation = new QgsTextAnnotation();
m_annotation->setMapPosition(QgsPointXY(116, 40));
m_annotation->setFrameSizeMm(QSizeF(50, 25));
auto _t = new QgsMapCanvasAnnotationItem(m_annotation, _canvas);
}
void setPos(QgsPointXY _point)
{
m_annotation->setMapPosition(_point);
}
void setString(QString _string)
{
auto _annotationString =make_shared<QTextDocument>(_string);
m_annotation->setDocument(_annotationString.get());
}
private:
QgsTextAnnotation* m_annotation;
};
使用:
auto biaopai_ = new biaopai(m_canvas);
biaopai_->setString("属性一\n属性二");
biaopai_->setPos(QgsPointXY(93, 36));