for any one who reads this i did it using QEventFilter.
this topic was helpful: http://www.qtcentre.org/threads/6272...cking-on-image
this is the code i use:
in header file:
bool eventFilter(QObject *o, QEvent *e);
To copy to clipboard, switch view to plain text mode
in .cpp
//filter mouse tracking to the selection area only
if(o!= lblScrollImage) return false;
if(e
->type
()==QEvent::MouseMove){ ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
//polyPoints << QPoint(x.toInt(), y.toInt());
}
else if (e
->type
()==QEvent::MouseButtonPress) {
ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
ui->lineEditX->setText(x.toString());
ui->lineEditY->setText(y.toString());
polyPoints <<
QPoint(x.
toInt(), y.
toInt());
}
return false;
}
//filter mouse tracking to the selection area only
bool MainWindow::eventFilter(QObject *o, QEvent *e){
if(o!= lblScrollImage) return false;
if(e->type()==QEvent::MouseMove){
QMouseEvent *mev = static_cast<QMouseEvent*>(e);
QVariant x(mev->pos().x());
QVariant y(mev->pos().y());
ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
//polyPoints << QPoint(x.toInt(), y.toInt());
}
else if (e->type()==QEvent::MouseButtonPress)
{
QMouseEvent *mev = static_cast<QMouseEvent*>(e);
QVariant x(mev->pos().x());
QVariant y(mev->pos().y());
ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
ui->lineEditX->setText(x.toString());
ui->lineEditY->setText(y.toString());
polyPoints << QPoint(x.toInt(), y.toInt());
}
return false;
}
To copy to clipboard, switch view to plain text mode
regards,
ahmed
Bookmarks