调整QDockWidget的大小 [英] resize a QDockWidget

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

问题描述

我有一个 QMainWindow ,其中包含多个 QDockWidget 。一次只能显示其中一个。我的问题是:

I have a QMainWindow that contains several QDockWidgets. Only one of them should be shown at a time. My Problem is:

当我隐藏一个dockWidget并显示另一个,新显示的大小是相同的只是隐藏,无论什么QSizePolicys,sizeHint,sizeConstraint我设置!我想要新显示的恢复自己的最后尺寸,但我找不到任何方法来调整 QDockWidget ,而不固定其大小 setMinimumSize setMaximumSize

When I hide a dockWidget and show another, the size of the newly shown is the same as the just hidden, no matter what QSizePolicys, sizeHint, sizeConstraint I set! I want the newly shown to restore its own last size but I can't find any method to resize a QDockWidget, without fixing its size with setMinimumSize and setMaximumSize.

其实有一种方法,但我认为它很丑陋:

In fact there is one way but I consider it very ugly:

setMinimumWidth(500);
setMaximumWidth(500);
qApp().processEvents();
setMinimumWidth(0);
setMaximumWidth(9999);

必须有更好的方法吗?任何建议?

There must be a better way?! Any suggestions?

推荐答案

我试过你的问题中建议的解决方案,它适用于我,虽然有一个丑陋的闪光小部件通过额外的绘制周期。我没有找到一个更好的方法,所以我会使用它现在,直到Qt发布更好的支持QDockWidget。

I tried the solution you suggested in your question and it works for me, although there is an ugly flash while the widget goes through an extra paint cycle. I haven't found a better way, so I'll use it for now until Qt releases better support for QDockWidget.

我希望有更多的功能添加到QDockWidget API。这是一个伟大的API,但有几个领域,仍然非常缺乏。例如,此建议方法可获取标签式QDockWidget的索引(从Qt FAQ)很繁琐,容易出错。

I'm hopeful that there will be more functionality added to the QDockWidget API. It's a great API, but there are several areas that are still sorely lacking. For example, this suggested method of obtaining the index of a tabbed QDockWidget (right from the Qt FAQ) is cumbersome and error prone.

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

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