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.
Thank you
We can set the size of label using resize() method and size can be adjusted with respect to the content using adjustSize() method. In this article, we will see how we can access the size. In order to do so we will use size() method. This method returns the Qsize object which is the parameter of resize() method.
You can call the 'size' function from any widget. If you call this from the main window it will return the size of the main window. QSIze size = this->size();
In PyQt, layout managers are classes that provide the required functionality to automatically manage the size, position, and resizing behavior of the widgets in the layout. With layout managers, you can automatically arrange child widgets within any parent, or container, widget.
Widgets are the basic building blocks for graphical user interface (GUI) applications built with Qt. Each GUI component (e.g. buttons, labels, text editors) is a widget that is placed somewhere within a user interface window, or is displayed as an independent window.
For getting Qt Widget size:
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
mainWindow = QtGui.QWidget()
width = mainWindow.frameGeometry().width()
height = mainWindow.frameGeometry().height()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With