Qt QStackedWidget 调整大小问题 [英] Qt QStackedWidget Resizing Issue

查看:295
本文介绍了Qt QStackedWidget 调整大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 QStackedWidget,其中包含 3 个不同的 QWidget.QWidget 的最小尺寸为 (350x200)、(200x100) 和 (450x450).

I have a simple QStackedWidget with 3 different QWidgets in it. The minimum sizes of the QWidgets are (350x200), (200x100), and (450x450).

所以我遇到的问题是当我调整 QStackedWidget 的大小时,它的最小大小是其中最大的 QWidget.因此,如果我切换到第二个 QWidget(即大小为 (200x100) 的 QWidget),则 QStackedWidget 的大小只会缩小 (450x450),因为其中有最大的 QWidget.我希望它缩小以适应当前显示的 QWidget,并删除最小尺寸.

So the problem I'm having is when I resize the QStackedWidget, it has a minimum size of the largest QWidget within it. So if I switch to the second QWidget, (which is the QWidget with the size of (200x100)), the QStackedWidget will only size down (450x450) because of the largest QWidget inside of it. I would like it to size down to fit the current QWidget being displayed, and remove that minimum size.

推荐答案

我认为最直接的解决方案是将 QStackedWidget 子类化并覆盖 sizeHint 和 minimumSizeHint 以返回当前小部件的提示,而不是所有小部件的最大值.例如:

I think that the most straightforward solution is to subclass QStackedWidget and override sizeHint and minimumSizeHint to return the hint for the current widget instead of the maximum of all widgets. For example:

class StackedWidget : public QStackedWidget
{
  QSize sizeHint() const override
  {
    return currentWidget()->sizeHint();
  }

  QSize minimumSizeHint() const override
  {
    return currentWidget()->minimumSizeHint();
  }
};

这篇关于Qt QStackedWidget 调整大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆