Can't Create a Welcome Screen Which but the formatting of the layout isn't currently working

后端 未结 1 1587
独厮守ぢ
独厮守ぢ 2021-01-27 20:29

Currently I am trying to make a layout that looks like this:

The left side will redirect a user to a unique create account page depending on which button they c

相关标签:
1条回答
  • 2021-01-27 20:54

    I would suggest using QGridLayout on the central widget of your main window. I've used two QSpacerItems to keep the widgets centered between the title label and the bottom. Btw, the style sheet QWidget {background-color: white;} will apply to everything that inherits from QWidget, including all the buttons and labels, not sure if you want that.

    class MyWindow(QtWidgets.QMainWindow):
    
        def __init__(self):
            super().__init__()
            self.setWindowTitle("Public Transport Application")
            self.setGeometry(200, 200, 800, 500)
            self.setWindowIcon(QIcon('Icon.jpg'))
            self.showMaximized()
            self.welcomePage()
    
        def welcomePage(self):
            centralWidget = QtWidgets.QWidget()
            self.setCentralWidget(centralWidget)
            grid = QtWidgets.QGridLayout(centralWidget)
            grid.setVerticalSpacing(40) # Vertical space between widgets
    
            title = QtWidgets.QLabel('Welcome to the Queensland Transport Application')
            title.setObjectName('titleOfPage')
            title.setAlignment(Qt.AlignCenter)
            title.setFixedHeight(100)
    
            grid.addWidget(title, 0, 0, 1, 2)
            grid.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding), 1, 0, 1, 2)
            grid.addWidget(QLabel('Text'), 2, 0, Qt.AlignHCenter)
            grid.addWidget(QPushButton('Button 1'), 3, 0, Qt.AlignHCenter)
            grid.addWidget(QPushButton('Button 2'), 4, 0, Qt.AlignHCenter)
            grid.addWidget(QPushButton('Button 3'), 5, 0, Qt.AlignHCenter)
            grid.addWidget(QPushButton('Button'), 2, 1, 4, 1, Qt.AlignHCenter)
            grid.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding), 6, 0, 1, 2)
    
    0 讨论(0)
提交回复
热议问题