代码:
1.重写鼠标事件
// 创建一个自己的类(*.h)
class myMapCanvas : public QgsMapCanvas
{
Q_OBJECT
public:
myMapCanvas(QWidget *parent);
~myMapCanvas();
signals:
void sendXY(QPoint point);
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *e);
};
// 创建一个自己的类(*.cpp)
void myMapCanvas::mouseDoubleClickEvent(QMouseEvent *e)
{
if(this->cursor().shape() == Qt::CrossCursor)
{
if (e->button() == Qt::LeftButton)
{
QPoint p;
p.setX(e->pos().x());
p.setY(e->pos().y());
emit sendXY(p);
}
}
}
2.实现识别功能
// (*.h)
// 识别用的槽函数
private slots:
void act_open_triggered();
void act_identify_triggered();
void getCurrentXY(QPoint point);
private:
// 创建画布
myMapCanvas *canvas;
//(*.cpp)
canvas = new myMapCanvas(this);
ui.tabWidget->addTab(canvas, " ");
ui.tabWidget->tabBar()-