Hi all,
I finally managed to find out what was the problem. The fix is the following
@@ -26,7 +26,7 @@ void MainWindow::mousePressEvent(QMouseEvent* event)
// If a QLabel contains the mouse pointer, then this is the QLabel that was selected
QList<QLabel*> qLabelList = ui->videoStreamsFrame->findChildren<QLabel*>();
foreach(QLabel *l, qLabelList) {
- QPoint mappedMousePosition = l->mapFromGlobal(mousePosition);
+ QPoint mappedMousePosition = l->mapToParent(l->mapFromGlobal(mousePosition));
if (l->geometry().contains(mappedMousePosition)) {
rubberBand = new QRubberBand(QRubberBand::Rectangle, l);
rubberBand->setGeometry(l->rect());
So, the mapFromGlobal() is translating the global coordinates to widget coordinates and the geometry(), where we use in order to check if the mouse coordinates are contained in the label, has the coordinates relative to the parent widget. So, we need to map the mouse coordinates to the parent widget, hence the function mapToParent().
Kind regards,
Stavros