Qt贴图实现地图标记效果

时间:2023-03-10 06:54:01
Qt贴图实现地图标记效果
#include "wgtmap.h"
#include "ui_wgtmap.h"
#include <QPainter> #define IMG_MARK_WIDTH 48
#define IMG_MARK_HEIGHT 48 #define IMG_BG_WIDTH 1842
#define IMG_BG_HEIGHT 1080 WgtMap::WgtMap(QWidget *parent) :
QWidget(parent),
ui(new Ui::WgtMap)
{
ui->setupUi(this); this->resize(IMG_BG_WIDTH, IMG_BG_HEIGHT); m_list_pos.clear();
m_list_labl.clear(); m_list_pos.append(QPoint(, ));
m_list_pos.append(QPoint(, ));
m_list_pos.append(QPoint(, ));
m_list_pos.append(QPoint(, ));
m_list_pos.append(QPoint(, ));
m_list_pos.append(QPoint(, )); for(int i=;i<;i++)
{
QLabel *lbl = new QLabel(this);
lbl->setFixedSize(IMG_MARK_WIDTH, IMG_MARK_HEIGHT);
lbl->setStyleSheet("background:transparent;image:url(image/pos_blue.png);");
lbl->move(m_list_pos.at(i));
} } WgtMap::~WgtMap()
{
delete ui;
} void WgtMap::paintEvent(QPaintEvent *event)
{
QPainter painter(this); //地图
painter.drawPixmap(,, , , QPixmap("D:\\worklog\\12\\19\\map.png"));
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::red, )); QPainterPath path(m_list_pos[]);
for (int i = ; i < m_list_pos.size(); ++i)
{
//微调折线点
QPointF pos_point(m_list_pos[i].x()+IMG_MARK_WIDTH/, m_list_pos[i].y()+IMG_MARK_HEIGHT);
path.lineTo(pos_point);
} painter.drawPath(path); return QWidget::paintEvent(event);
}