画面ウィジェットが入ったコンテナであるQtを使ってプレビューオブジェクトを作成しました。アスペクト比を正しくするには、画面の幅を変更するときに高さも変更する必要があります。
これにより、画面がスクロール領域内にあり、その高さがスクロールバーが入る特定のポイントを超えると、問題が発生します。これにより、幅が狭くなり、高さを低くする必要があります。これにより、スクロールバーでループが発生する可能性があります。出入りし続けます。
私がこれを修正しようとした1つの方法は、必要なサイズを取得し、サイズの計算と設定を担当する関数の反復回数にわたって平均することです。平均が必要なサイズと大幅に異ならない場合、サイズは変更されません。 。これで問題は解決しましたが、私には最適とは言えません...
誰かがこの問題を修正する方法のアイデアを持っているかどうか疑問に思いますか?
//********************************************************************************
/// \brief Called to make the size of the preview pane the correct size
void PreviewDisplayWidget::SetSizeOfScreen()
{
double aspect_ratio = _preview_controls->_video_settings.getVideoFormat().GetAspectRatio();
// Calculate the new minimum size
int minimum_size = _container->width()/aspect_ratio;
// HACK TO FIX ISSUE WITH RESIZING:
// The preview sets its height from the width, if the width is changed, so will the height.
// This causes an issue with the scroll area as it can be in a situation that will cause the
// scroll area to get thinner (due to scroll bars being added), causing the width of the widget
// to change, therefore causing the height to change. Which can be enough to make the scroll bar go
// away. This can loop and cause a stack overflow.
//
// Store the last 10 sizes.
_previous_sizes.push_back(minimum_size);
const int sizes_to_scan = 10;
if (_previous_sizes.size() > sizes_to_scan)
{
_previous_sizes.pop_front();
}
int sum = 0;
for (auto i =_previous_sizes.begin(); i != _previous_sizes.end(); i++)
{
sum += *i;
}
double average = (double) sum / (double) _previous_sizes.size();
std::cout << "Average " << average << std::endl;
bool change_in_average = false;
// Significant change in average means a size change should occur
if (average > minimum_size + 5 || average < minimum_size - 5)
{
change_in_average = true;
}
if (change_in_average || _previous_sizes.size() < sizes_to_scan - 1)
{
_preview_frame->setMinimumHeight(minimum_size);
std::cout << "Preview sizes " << minimum_size << std::endl;
_preview_frame->updateGeometry();
}
SetPreviewSize();
}