setGeometry
时间: 2024-05-15 22:19:26 浏览: 50
setGeometry is a method in Qt programming that is used to set the size and position of a widget (such as a button or label) on the screen. The setGeometry method takes four arguments: x, y, width, and height. The x and y arguments specify the position of the widget on the screen, while the width and height arguments determine the size of the widget.
For example, the following code sets the position of a QPushButton widget to (100, 100) and sets its size to 100x50 pixels:
```python
button = QPushButton("Click me", parent)
button.setGeometry(100, 100, 100, 50)
```
This code creates a button with the label "Click me" and sets its position to (100, 100) and its size to 100x50 pixels. The parent argument specifies the parent widget of the button.
The setGeometry method is commonly used in Qt programming to position and size widgets on the screen. It is often used in conjunction with layout managers to create responsive and dynamic user interfaces.
阅读全文