[BeYourself] PyQt Widgets & Layouts

5763 ワード

Widgets


tutorials
WidgetWhat it doesQCheckboxA checkboxQComboBoxA dropdown list boxQDateEditFor editing dates and datetimesQDateTimeEditFor editing dates and datetimesQDialRotatable dialQDoubleSpinboxA number spinner for floatsQFontComboBoxA list of fontsQLCDNumberA quite ugly LCD displayQLabelJust a label, not interactiveQLineEditEnter a line of textQProgressBarA progress barQPushButtonA buttonQRadioButtonA toggle set, with only one active itemQSliderA sliderQSpinBoxAn integer spinnerQTimeEditFor editing times

Layouts


tutorials
LayoutBehaviourQHBoxLayoutLinear horizontal layoutQVBoxLayoutLinear vertical layoutQGridLayoutIn indexable grid XxYQStackedLayoutStacked (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ネストされたレイアウトを使用できます.
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)