ここでの問題は、サイズx x yの表示ウィンドウがあり、スクロールせずにウィンドウ内に画像を表示し、アスペクト比を4:3に維持する必要があることです。次のコードスニペットがあります。
// Lock the current height, calculate new width of the canvas and scale the viewport.
// get width of the movie canvas
qreal width = canvas_->width();
// Find the height of the video
qreal height = (width/4.0) * 3;
// find original width and height for video to calculate scaling factor
qreal videoWidth = movieData_->GetWidth();
qreal videoHeight = movieData_->GetHeight();
// calculate scaling factor
qreal scaleFactorWidth = width/videoWidth;
qreal scaleFactorHeight = height/videoHeight;
もちろん、高さまたは幅のいずれかを「アンカー」として使用すると、いずれかの方法で新しい画像がスクロールします(元の画像が最初にウィンドウよりも大きいと仮定します)。所定のサイズに収まるアスペクト比4:3の寸法を見つけるにはどうすればよいですか?
編集 スケーリングを行うには、xとyの両方のスケール係数を渡す必要があります
canvas_->scale(scaleFactorWidth, scaleFactorHeight);