Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I connect 2 ui like login page and mainpage?



  • Capture.PNG

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(600, 400)
            MainWindow.setMaximumSize(QtCore.QSize(600, 400))
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.frame = QtWidgets.QFrame(self.centralwidget)
            self.frame.setStyleSheet("background-color: rgb(56, 56, 56);")
            self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame.setObjectName("frame")
            self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.frame)
            self.horizontalLayout_2.setObjectName("horizontalLayout_2")
            spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
            self.horizontalLayout_2.addItem(spacerItem)
            self.pushButton = QtWidgets.QPushButton(self.frame)
            self.pushButton.setObjectName("pushButton")
            self.horizontalLayout_2.addWidget(self.pushButton)
            spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
            self.horizontalLayout_2.addItem(spacerItem1)
            self.horizontalLayout.addWidget(self.frame)
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtWidgets.QMenuBar(MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 600, 21))
            self.menubar.setObjectName("menubar")
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtWidgets.QStatusBar(MainWindow)
            self.statusbar.setObjectName("statusbar")
            MainWindow.setStatusBar(self.statusbar)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
            self.pushButton.setText(_translate("MainWindow", "Click me"))
    
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())
    

    When i click a button on this page , i want main page(below) to show up .it is like login page and main page but these are example.

    Capture_2.PNG

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(800, 600)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.frame = QtWidgets.QFrame(self.centralwidget)
            self.frame.setStyleSheet("background-color: rgb(39, 39, 39);")
            self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame.setObjectName("frame")
            self.label = QtWidgets.QLabel(self.frame)
            self.label.setGeometry(QtCore.QRect(390, 140, 231, 241))
            self.label.setStyleSheet("font-size:20px;")
            self.label.setObjectName("label")
            self.horizontalLayout.addWidget(self.frame)
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtWidgets.QMenuBar(MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
            self.menubar.setObjectName("menubar")
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtWidgets.QStatusBar(MainWindow)
            self.statusbar.setObjectName("statusbar")
            MainWindow.setStatusBar(self.statusbar)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
            self.label.setText(_translate("MainWindow", "Hello!"))
    
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())
    

    Let me know how to connect these.I dont know how to call this processing .i'm beginner of qt.I got downvotings and closed question in stackoverflow.It is also better if you can share a link for me to learn that.Thanks:D


  • Lifetime Qt Champion

    @KaungSat You can use https://doc.qt.io/qt-5/qstackedwidget.html where you define pages you need and then connect a slot to https://doc.qt.io/qt-5/qabstractbutton.html#clicked signal where you call https://doc.qt.io/qt-5/qstackedwidget.html#currentIndex-prop to show the next page.


  • Lifetime Qt Champion

    @KaungSat You can use https://doc.qt.io/qt-5/qstackedwidget.html where you define pages you need and then connect a slot to https://doc.qt.io/qt-5/qabstractbutton.html#clicked signal where you call https://doc.qt.io/qt-5/qstackedwidget.html#currentIndex-prop to show the next page.



  • This post is deleted!


  • @jsulm Thanks.i can finally figure it out .i thought my question is too stupid when i asked this in stackoverflow.but it is ok now.Thanks for your help!


Log in to reply