Pyqt如何获取小部件的尺寸

2022-01-18 00:00:00 python pyqt widget size

问题描述

我目前正在开发一个无法使用模式窗口的应用程序(由于某些应用程序限制).但是,在某些情况下,我想模拟一个弹出窗口.为此,我动态创建了一个以 centralwidget 作为父级的小部件,并使用 move() 方法将其放置在我想要的位置.我想知道是否有办法在给定时间获取小部件的尺寸(考虑到 mainWindow 可以随时调整大小),以便我能够将占位符弹出窗口(一个简单的小部件)居中中央小部件.

I am currently developing an application in which i cannot use modal windows (due to some application constraints). However, in some cases i would like to simulate a popup window. To do so i dynamically create a widget that has the centralwidget as parent and i use the move() method to place it where i want. I would like to know if there is a way to get a widget's dimensions at a given time (considering the mainWindow can be resized at any time) so that i will be able to center the placeholder popup (a simple widget) at the middle of the centralwidget.

谢谢


解决方案

你可以使用frameGeometrygeometry 取决于 您的需求.

相关文章