#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);
}

 

posted on 2018-12-19 16:46  邶风  阅读(1118)  评论(0编辑  收藏  举报