Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyqt how to get a widget's dimensions

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

like image 822
ibi0tux Avatar asked Mar 04 '13 14:03

ibi0tux


People also ask

How to get size of a label in PyQt5?

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.

How to get size of window Qt?

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();

What is layout in pyqt5?

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.

What is a widget in PyQt?

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.


1 Answers

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()
like image 81
subin george Avatar answered Sep 18 '22 17:09

subin george