PDA

View Full Version : A question about coordinate transform



lazy_learner
23rd May 2013, 00:04
I reimplement the mousePressEvent and use QwtPlot::invTransform to transform the coordinate.But it don't work as I expected.


void plot :: mousePressEvent(QMouseEvent *e)
{
if(e->button() == Qt::LeftButton)
{
QPointF temp = e->posF();
QMessageBox::information(this,tr("information!"),tr("the original x posation is %1 and y posation is %2").arg(temp.x()).arg(temp.y()),QMessageBox::Ok|QMes sageBox::Default,QMessageBox::NoButton,QMessageBox ::NoButton);
//picker->invTransform()
temp.setX(this->invTransform(QwtPlot::xBottom,temp.x()));
temp.setY(this->invTransform(QwtPlot::yLeft,temp.y()));

QMessageBox::information(this,tr("information!"),tr("changed x posation is %1 and y posation is %2").arg(temp.x()).arg(temp.y()),QMessageBox::Ok|QMes sageBox::Default,QMessageBox::NoButton,QMessageBox ::NoButton);

}

}


well , it look just like 90569057

but the real coordinate in the axis is is not x=688.05 and y=553.371

lazy_learner
24th May 2013, 06:29
Can anyone help me ?

lanz
24th May 2013, 09:19
Your code seems correct to me.
How do you know that x=688.05 and y=553.371 isn't correct values?
Post a screenshot maybe where it is clearly visible, it may give a pointer.
Also it helps if you attach minimal compilable project.

lazy_learner
24th May 2013, 12:40
because the value on the QwtPlotpicker donesn't is not 688.05 553.371... wait a moment , I 'll post a screenshot...

Added after 1 41 minutes:

906590669066

Uwe
25th May 2013, 15:28
Wrong widget: canvas != plot.

You have to install an event filter for the canvas - or with Qwt 6.1 you can overload the mouse event handler of it. If you want to keep your code you have to translate the coordinates of the mouse click into coordinates that are relative to the canvas - f.e. with mapToGlobal() and mapFromGlobal() - or simply by subtracting the position of the canvas.

Uwe

lazy_learner
25th May 2013, 15:52
yes ,you're right. In the first version of my program. I solved this problem by subtract a certain value , but I don't know why and how it happen.Er.. But how can I know the position of the canvas ?

Uwe
26th May 2013, 10:26
Use QWidget::pos() or QWidget::geometry() - the canvas is a child of the plot widget.

Uwe

lazy_learner
26th May 2013, 15:31
thank you~you're very helpful~