본문 바로가기
PyQt5_

Sizing windows and widgets

by 자동매매 2023. 3. 10.

 

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)

'PyQt5_' 카테고리의 다른 글

Layouts  (0) 2023.03.11
Widgets  (0) 2023.03.10
Signals & Slots  (0) 2023.03.10
빈 창  (0) 2023.03.10
index  (0) 2023.03.10

댓글