1

i am using the c++ api qgis 2.8.2 i have a strange problem when i want to use the pantool for my canvas

i used this code :

mpPanTool = new QgsMapToolPan((QgsMapCanvas*)mpMapCanvas);
((QgsMapToolPan*)mpPanTool)->activate();
((QgsMapCanvas*)mpMapCanvas)->setMapTool((QgsMapToolPan*)mpPanTool);

building is good, when i launch my application and i load a raster or a s57 map if i click on the map or on the canvas nothing happen till i move the mouse when i move the mouse it seems that the map change the upper left origin point and set a new one at the mouse position by example if i left click on the map and i move the mouse, the map is automatically centered with the upper left point of the canvas at the mouse coordinate

perhaps i forget something, pan works but the problem is this coordinate change

please help

1

i have found a solution in my application i have a raster, and i want to pan the raster

here is the code i have

void CMyQgsMapCanvas::mousePressEvent(QMouseEvent* pevent)
{

    mMouseEvent = new QMouseEvent(pevent->type() , pevent->pos(), pevent->globalPos(), pevent->button(),pevent->buttons(), pevent->modifiers() );
    mClickTimer.start(220);
    qDebug() << "Button ::" << mMouseEvent->button();

    if ( pevent->button() == Qt::LeftButton )
    {
        mCanvasProperties->panSelectorDown = true;

        QPoint  lPos = pevent->pos();
        mCanvasProperties->rubberStartPoint = lPos;
    }
    pevent->ignore();
}

void CMyQgsMapCanvas::mouseReleaseEvent( QMouseEvent* pevent)
{
    mLeftButtonPressed=false;
    if ( pevent->button() == Qt::LeftButton )
    {
        mCanvasProperties->panSelectorDown = false;
        mCanvasProperties->mouseButtonDown = false;
    }
    pevent->ignore();
}

void CMyQgsMapCanvas::mouseMoveEvent(QMouseEvent* pevent)
{

    QPoint  lPos = pevent->pos();

    if(mCanvasProperties->mouseButtonDown == true)
    {
        panActionEnd(lPos);
        mCanvasProperties->rubberStartPoint = lPos;
    }

    setCursor(Qt::ArrowCursor);
    QgsMapCanvas::mouseMoveEvent(pevent);
    pevent->ignore();
}

it works well after loading the raster in the mapcanvas i can move it by moving the mouse keeping the left button pressed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.