import sys
from PyQt6.QtCore import QSize, Qt
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton
# Subclass QMainWindow to customize your application's main window
class MainWindow (QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("My App")
button = QPushButton("Press Me!")
self.setFixedSize(QSize( 400 , 300 ))
# Set the central widget of the Window.
self.setCentralWidget(button)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app. exec ()
- In Qt, sizes are defined using a QSize object. This accepts width and height parameters in that order.
For example, the following will create a fixed size window of 400x300 pixels.
self.setFixedSize(QSize(400, 300))
- .setMinimumSize() 및 .setMaximumSize()를 호출하여 각각의 Widget에 대해서 최소 및 최대 크기를 설정할 수도 있습니다.
Note
Windows 및 Linux에서 기본적으로 maximize control은 비활성화되어 있습니다.
macOS에서는 앱을 최대화하여 화면을 채울 수 있지만 central widget의 크기는 조정되지 않습니다.
Note
geometry 메서드 대안 : setCentralWiget(대상Widget)
댓글