Hi everyone,
I am implementing a rolling spectrogram in Qt by subclassing a QChartView widget (which inherits from QGraphicsView) and adding a QGraphicsPixmapItem to the QGraphicsScene. The pixmap is updated when a separate helper class send a new spectrogram pixmap. So far so good. Resizing the video also has been implemented fine.

I've also added a zoom function with the rubberband selection tool. I'm doing this by catching mousePress and mouseRelease events and calculating the rectangle, which is then passed to the helper class.
Qt Code:
  1. void CustomChartView::mousePressEvent(QMouseEvent *event)
  2. {
  3. zoomRectangle.setTopLeft(QPointF(this->mapToScene(event->pos())).toPoint());
  4.  
  5. QChartView::mousePressEvent(event);
  6. }
  7.  
  8. void Velo::UI::CustomChartView::mouseReleaseEvent(QMouseEvent *event)
  9. {
  10. zoomRectangle.setBottomRight(QPointF(this->mapToScene(event->pos())).toPoint());
  11.  
  12. if(zoomRectangle.topLeft() != zoomRectangle.bottomRight()) // Exclude one pixel cases (accidental touches)
  13. emit zoomedIn(zoomRectangle);
  14.  
  15. QChartView::mouseReleaseEvent(event);
  16. }
To copy to clipboard, switch view to plain text mode 

The helper class then emits a subset of the original image, scaled to the full image area:
Qt Code:
  1. emit newSpectrogramImage(((spectrogramImage.scaled(spectrogramImageScaledSize)).copy(spectrogramZoomRectangle)).scaled(spectrogramImageScaledSize));
To copy to clipboard, switch view to plain text mode 

This works fine, but the trouble arises when I also want to resize my application. Since the zoomRectangle is stored with fixed coordinates, and the spectrogramImageScaledSize changes with the resize, the zoom coordinates are not valid. I would like to know if there is a way to tranform the coordinates of the zoomRectangle also when resizing, or if there is an easier method to implement this.

The other thing is that this way of zooming only works for zooming into the image once. If I want to zoom further into the zoomed image, the image emitted will be with new coordinates but with respect to the original image. Is there a way to implement this as well? Maybe if there was a way to scale the second zoom coordinates with respect to the original zoom rectangle?

Sorry for the long post, but I hope I explained my problem clearly.

Regards,
apakhira