Qt小部件覆盖 [英] Qt Widget Overlays

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

问题描述

如何在Qt中覆盖小部件?

How do I overlay widgets in Qt?

我想创建一些小部件并将它们放置在布局之外,但是当其他一些小部件的几何形状更改时,我会调整它们的大小和位置.

I want to create some widgets and place them out-of-layout, but rather tweak their size and position when some other widget's geometry is changed.

类似于屏幕截图上的按钮:

Something like the buttons on the screenshot:

推荐答案

您只需要创建QPushButton(或任何QWidget),指示其父QWidget,然后显示它即可.

You just need to create your QPushButton (or any QWidget), indicate its parent QWidget and then display it.

请勿将其添加到父版式,否则您将无法根据需要移动它.

Don't add it to the parent layout else you will not be able to move it as you want.

别忘了指出它的父级,否则它将显示为独立的QWidget.

Don't forget to indicate its parent else it will be displayed as independant QWidget.

在这些情况下,您的QPushButton将被视为QWidget的子级,而不是父级布局的成员.因此,它将是浮动"子代,您在调整父代QWidget大小时必须管理它的行为.

In these conditions your QPushButton will be considered as child of the QWidget but not member of the parent's layout. So it will be a "floating" child and you must manage it's behaviour when resizing parent's QWidget.

如果您希望所有叠加按钮的行为统一,则应子类 QLayout 并重新定义成员的行为.

If you want a unified behaviour for all overlay buttons, you should subclass QLayout and redefine members bahaviour.

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

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