防止QDockWidget自动调整大小行为 [英] Prevent QDockWidget autosizing behaviour

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

问题描述

Qt 5.5.0

在我的应用程序中,我有一个QGraphicsView作为主窗口小部件,还有一个用于属性的QDockWidget. 目的是让用户在图形视图中选择一个项目,并根据该项目显示该项目的适当属性.

In my application, I have a QGraphicsView as the main widget and a QDockWidget for properties. The goal is for the user to select an item in the graphics view and, depending on the item, present the appropriate properties for that item.

我通过拥有一个属性管理器窗口小部件来实现此目的,该窗口小部件的布局包含每个属性窗口小部件.我已经连接了信号和插槽以获取当前选定的项目,然后将所需的小部件show()和其余的hide().

I achieve this by having a properties manager widget with a layout containing each of the properties widgets. I have signals and slots hooked up for getting the currently selected item, and then show() the widget I need and hide() the rest.

这很好用!但是,选择不同的项目时,停靠栏将根据显示的窗口小部件收缩或增大.这是很刺耳的,而且很烦人.事实是,当用户手动调整扩展坞的大小时,它会保持该大小.我希望保留的大小是默认大小,而不是这种自动调整大小的行为.

This works great! However, when selecting different items, the dock shrinks or grows based on the shown widget. It is very jarring, and rather annoying. The thing is though, that when the user manually resizes the dock, it maintains that size. I want the maintained size to be default rather than this autosizing behaviour.

我尝试过的事情:

我尝试过更改底座和主窗口的sizePolicy():无效.

I've tried changing the sizePolicy() of the dock and the mainwindow: No effect.

我为我的属性管理器设置了最小大小,这确实可以防止显示较小的一组属性时扩展坞缩小.但是,我仍然希望用户能够根据需要将扩展​​坞缩小到较小的尺寸,并且这种方法可以防止...

I've set a minimum size for my properties manager which does indeed prevent the dock from shrinking when a smaller set of properties is shown. However, I still want the user to be able to shrink the dock to a smaller size if they wish, and this method prevents that...

结论:

当用户调整停靠站的大小以告知其保持该大小时,是否设置了标志或设置的内容?如果是这样,有没有办法手动设置它?

Is there a flag or something that is set when the user resizes the dock that tells it to maintain that size? If so, is there a way to manually set it?

我还没有尝试继承QDockWidget或QMainWindow.有没有可以我用来实现正确行为的方法?

I haven't tried subclassing QDockWidget or QMainWindow yet. Is there a method(s) that I can override to achieve the correct behaviour?

感谢您的帮助!

推荐答案

所有必要的就是打电话

setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);

在我的属性管理器小部件(QDockWidget的中央小部件)的构造函数中

in the constructor of my properties manager widget (the central widget of the QDockWidget)

我还重载了sizeHint()函数以返回可观的默认大小.

I also overloaded the sizeHint() function to return a respectable default size.

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

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