Qt调整窗口大小以适应滚动区域中的宽高比问题 您所在的位置:网站首页 div自适应窗口高度 Qt调整窗口大小以适应滚动区域中的宽高比问题

Qt调整窗口大小以适应滚动区域中的宽高比问题

2023-03-14 14:21| 来源: 网络整理| 查看: 265

我已经使用Qt制作了一个预览对象,它是一个包含其中的屏幕控件的容器。为了使其纵横比正确,当屏幕宽度改变时,高度也需要改变。Qt调整窗口大小以适应滚动区域中的宽高比问题

由于屏幕位于滚动区域内部,因此当滚动条的高度超出滚动条进入的某个点时,会导致出现问题。这会减小宽度,因此需要降低高度,这会导致循环滚动条不停地进出。

我试图解决这个问题的一种方法是,在负责处理和设置大小的函数的迭代中,取所需的大小和平均值,如果平均值与所需大小没有显着差异大小不会改变。这有点解决了这个问题,但对我来说似乎并不理想......

我想知道是否有人有如何解决这个问题的想法?

//******************************************************************************** /// \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


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有