zoukankan      html  css  js  c++  java
  • 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(200, 200));
        m_list_pos.append(QPoint(240, 250));
        m_list_pos.append(QPoint(300, 300));
        m_list_pos.append(QPoint(330, 350));
        m_list_pos.append(QPoint(400, 400));
        m_list_pos.append(QPoint(500, 700));
    
    
        for(int i=0;i<6;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(0,0, 1842, 1416, QPixmap("D:\worklog\12\19\map.png"));
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.setPen(QPen(Qt::red, 2));
    
        QPainterPath path(m_list_pos[0]);
        for (int i = 1; i < m_list_pos.size(); ++i)
        {
            //微调折线点
            QPointF pos_point(m_list_pos[i].x()+IMG_MARK_WIDTH/2, m_list_pos[i].y()+IMG_MARK_HEIGHT);
            path.lineTo(pos_point);
        }
    
        painter.drawPath(path);
    
    
        return QWidget::paintEvent(event);
    }
  • 相关阅读:
    Centos 设置开机进图形界面/终端
    Ubuntu 开机慢(networking.service导致)
    Linux 内核下载地址
    C/C++中内存对齐
    编译器数据模型
    CPU中断
    sql语句
    mysql学习
    Active进阶
    SpringBoot整合ActiveMQ
  • 原文地址:https://www.cnblogs.com/zhangxuan/p/10144274.html
Copyright © 2011-2022 走看看