Pyqt how to get a widget's dimensions

pyqt get layout
pyqt widget
pyqt layout
pyqt nested layouts
pyqt find widget by name
pyqt findchildren
pyqt resize widget with window
get child widget pyqt

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

You can use frameGeometry or geometry depending on your needs.

get widgets by name from layout, The problem is that itemAt() function returns the QLayoutItem and not a widget. So you have to call the QLayoutItem::widget() function to get the containing  To get a widget from a QLayout, you have to call its itemAt(index) method. As the name of this method implies, it will return an item instead of a widget. Calling widget() on the result will finally give you the widget: myWidget = self.myLayout.itemAt(index).widget() To remove a widget, set the parent widget to None: myWidget.setParent(None)

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

PyQt5 Widgets, Widgets. Martin Fitzpatrick Getting started with PyQt5. Read time 20:00 In Qt (​and most User Interfaces) 'widget' is the name given to a component of the UI  A QToolBar widget is a movable panel consisting of text buttons, buttons with icons or other widgets. This is a preconfigured dialog with a text field and two buttons, OK and Cancel. The parent window collects the input in the text box after the user clicks on Ok button or presses Enter. Another commonly used dialog, a font selector widget is

For gettting screen size

import sys
from PyQt4 import QtGui, QtCore

app = QtGui.QApplication(sys.argv)

mainWindow = QtGui.QWidget()
screenShape = QtGui.QDesktopWidget().screenGeometry()
mainWindow.resize(self.screenShape.width(), self.screenShape.height())

Create custom GUI Widgets for your Python apps with , › moin › PyQt › Widgets in a layout The widgets in a QSplitter object are laid horizontally by default although the orientation can be changed to Qt.Vertical. Following are the methods and signals of QSplitter class − Methods & Description. Adds the widget to splitter’s layout. Returns the index of the widget in the layout. Inserts a widget at the specified index.

PyQt/Widgets in a layout, This shows basic widget creation, though most programs will tend to create and instantiate subclasses of QWidget or other widget classes for their  Actually, it does work. Problem is, your Test widget has a QPushButton without any layout management. So it can't calculate its minimumSize with taking the button into consideration. When you put that widget in a layout, it just shrinks to 0 (since a QWidget has no default minimumSize) and you don't see anything.

[PyQt] How to get the list of widgets names in a form, [PyQt] How to get the list of widgets names in a form. Simone simozack at​. Fri Mar 7 13:55:06 GMT 2008. Previous message: [PyQt] How to get the list of  PyQt5 widget positioning example The example below puts widgets on the absolute positions using the move() method. They are added to a PyQT5 window (QMainWindow) which has some properties set in initUI().

PySide2.QtWidgets.QWidget, Qt::WindowFlags f = 0 (where available) sets the window flags; the default is suitable for almost all widgets, but to get, for example, a window without a window  if you don't have a variable name for the widget at class or global level you still can remove from layout with layout.takeAt(index) and get the widget pointer from the QLayoutItem this functions returns with QLayoutItem.widget() method, in that case you don't need to assign to None the variable name because it is not referenced outside your function.

  • For those looking for actual QWidget size (inner size): If you want to know the size of the widget usable space (the inner space), you need to use geometry, not frameGeometry which adds the size of the window frame to the widget own size.
  • This is not a correct answer if you don't give a working example. Copy-pasting docs only is not an answer. Therefore @subin george gave the correct answers.
  • @GLHF although you are correct with your statement... OP doesn't give code. Its all theoretical; therefore I Avaris his theorectical answer is correct as well ;-))
  • two other useful parameters are: .left() and .top()