Hello, I recently had a question about how to trace coordinates of a QLabel using the mouse cursor. It worked well for what I thought of doing. What I want to do is the following, I have an image that I project on the screen through a QLabel, I include a function to trace the coordinates of this QLabel. Below a screen PrintScreen of my project:
ButIwillneedthevaluesofthesecorrectimagecoordinatestoworkonitinthefuture,buttheonlyvaluesthecursorgetsarethepixelvaluesofthesizeofmyQLabel.Forexample,QLabelhassize551x461,theimageisalready960x720.IsthereanywayIcancapturethecorrectpixelcoordinatesoftheimageintheQLabelwithdifferentsize?IsthereanymethodofconvertingthisdataintoQT?Iunderstandthatthisproblemseemstobetoocomplicated,butIthoughtitwouldnotbedifficulttotry.
BelowthecapturecodeoftheCoordinates:
voidmainwindow::on_ButtonAddFileira_clicked(){this->pTimer.disconnect();QImageimage;image.load("C:/Users/Syn/Desktop/TCC/Fotos Bolsão FEI/02 Bolsao_Cheio_Foreground.jpg");
//image = MatToQImage(this->ImagemBase.capturaImgBuffer());
ui->labelScreen->setPixmap(QPixmap::fromImage(image));
ui->labelScreen->setScaledContents(true);
connect(&cursorTimer, SIGNAL(timeout()), SLOT(cursor_timer_timeout()));
cursorTimer.start(50);
}
labelScreen is the Image Display QLabel, and in the code below label_X and label_Y are the coordinate labels on the screen.
void mainwindow::cursor_timer_timeout(){
QPoint cursorPos = ui->labelScreen->mapFromGlobal( QCursor::pos() );
int x = cursorPos.x();
int y = cursorPos.y();
ui->label_X->setNum(x);
ui->label_Y->setNum(y);
}
Thanks in advance for your help and attention, any little help will be welcome.