Skip to content
  • 0 Votes
    3 Posts
    222 Views
    B

    @jsulm said in Drawing QRubberBands with variabe size, but fixed aspect ratio: how to do it?:

    rubberBand->setGeometry(QRect(origin, event->pos()).normalized());

    Thanks. It is indeed as easy as you indicated!
    Regards
    Bertwim

  • 0 Votes
    4 Posts
    493 Views
    S

    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

  • 0 Votes
    8 Posts
    3k Views
    S

    @Vinod-Kuntoji

    No not working ,
    rubberBand->setPalette(Qt::transparent); removes the color from borders also..