[BeYourself] PyQt Widgets & Layouts

토즐라·2022년 4월 19일
0
post-thumbnail

Widgets

tutorials

WidgetWhat it does
QCheckboxA checkbox
QComboBoxA dropdown list box
QDateEditFor editing dates and datetimes
QDateTimeEditFor editing dates and datetimes
QDialRotatable dial
QDoubleSpinboxA number spinner for floats
QFontComboBoxA list of fonts
QLCDNumberA quite ugly LCD display
QLabelJust a label, not interactive
QLineEditEnter a line of text
QProgressBarA progress bar
QPushButtonA button
QRadioButtonA toggle set, with only one active item
QSliderA slider
QSpinBoxAn integer spinner
QTimeEditFor editing times

Layouts

tutorials

LayoutBehaviour
QHBoxLayoutLinear horizontal layout
QVBoxLayoutLinear vertical layout
QGridLayoutIn indexable grid XxY
QStackedLayoutStacked (z) in front of one another

QVboxlayout

filled from top to bottom.

QHboxlayout

filled from left to right.

QGridLaytout

widgets arranged in a grid

QStackedLayout

Multiple widgets in the same space




Nesting Layout

.addLayout 을 이용해 layout을 nesting 할 수 있음.

class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()

        self.setWindowTitle("My App")

        layout1 = QHBoxLayout()
        layout2 = QVBoxLayout()
        layout3 = QVBoxLayout()

        layout2.addWidget(Color('red'))
        layout2.addWidget(Color('yellow'))
        layout2.addWidget(Color('purple'))

        layout1.addLayout( layout2 )

        layout1.addWidget(Color('green'))

        layout3.addWidget(Color('red'))
        layout3.addWidget(Color('purple'))

        layout1.addLayout( layout3 )

        widget = QWidget()
        widget.setLayout(layout1)
        self.setCentralWidget(widget)
profile
Work Hard, Play Hard 🔥🔥🔥

0개의 댓글