Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Facing problems with switching through multiple windows in my GUI
QtWS25 Last Chance

Facing problems with switching through multiple windows in my GUI

Scheduled Pinned Locked Moved Solved General and Desktop
pyqt5
11 Posts 5 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahmed Zeid
    wrote on last edited by Ahmed Zeid
    #1

    Hello all,

    I am designing a multiple window GUI using Qt Designer, I have read in pretty much everywhere that it's not good practice to edit the code generated by pyuic5, and instead create a separate logic file that imports the windows into my subclasses. I did just that, and when I tried to move from the first to second window it works just fine, but for some reason I can't move from second to third window. However, if I am to start from the second window, it would move to the third just fine.

    I believe my mistakes have to do with OOP, as i am still new to it, but I can't figure out what is it exactly.
    So, will anyone please direct me into the way where I can solve this problem?
    Thank you.

    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtCore import QTimer, Qt
    
    from First import Ui_MainWindow
    from Second import Ui_Form 
    from Third import Ui_Form2
    
    
    class FirstWindow (QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self, parent=None):
            super(FirstWindow, self).__init__(parent)
            self.setupUi(self)
            
            #----------------------------------------------------------------------
            self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
            QTimer.singleShot (5000, self.secondscreen)
            #----------------------------------------------------------------------
        
        @QtCore.pyqtSlot()    
        def secondscreen(self):
            self.Form = QtWidgets.QWidget()
            self.ui = Ui_Form()
            self.ui.setupUi(self.Form)
            self.Form.showMaximized() 
            self.close()
            
            
    class SecondWindow (QtWidgets.QWidget, Ui_Form):
        def __init__(self, parent=None):
            super(SecondWindow, self).__init__(parent)
            self.setupUi(self)
    
         
            #----------------------------------------------------------------------
            self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
            self.pushButton.clicked.connect(self.thirdscreen)
            #----------------------------------------------------------------------
            
        @QtCore.pyqtSlot()    
        def thirdscreen(self):
            self.Form2 = QtWidgets.QWidget()
            self.ui = Ui_Form2()
            self.ui.setupUi(self.Form2)
            self.Form2.showMaximized() 
            self.close()
            
            
    class ThirdWindow (QtWidgets.QWidget, Ui_Form2):
        def __init__(self, parent=None):
            super(ThirdWindow, self).__init__(parent)
            self.setupUi(self)
            
            
    
            
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Software = FirstWindow()
        Software.show()
        sys.exit(app.exec_())
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Then it looks like you should rather use a QStackedWidget rather than re-create the widgets all the time and handle the switching at a higher level.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        Are you doing some kind of wizard ?

        Or do you want to go back and forth with them ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Are you doing some kind of wizard ?

          Or do you want to go back and forth with them ?

          A Offline
          A Offline
          Ahmed Zeid
          wrote on last edited by
          #3

          Hello, @SGaist, thank you for your reply.
          No, It's not a wizard. I should be able to go back and forth.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Then it looks like you should rather use a QStackedWidget rather than re-create the widgets all the time and handle the switching at a higher level.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            2
            • SGaistS SGaist

              Then it looks like you should rather use a QStackedWidget rather than re-create the widgets all the time and handle the switching at a higher level.

              A Offline
              A Offline
              Ahmed Zeid
              wrote on last edited by
              #5

              @SGaist You're absolutely right. The transition is much smoother now.

              One more question please, my first window is a loading screen like the one shown in the picture attached, and then the software windows themselves are in the QStackedWidget.

              In many other software, while the loading screen is showing, the software icon doesn't actually appear in the taskbar, instead it only appears once the actual software has started (The QStackedWidget in my case).
              Do you happen to know how to hide the icon from the taskbar while showing my loading screen (which is a QMainWindow btw) and then showing it later on?
              Thanks a lot.

              icepak-launch-workbench.3ea599da.png

              jsulmJ 1 Reply Last reply
              0
              • A Ahmed Zeid

                @SGaist You're absolutely right. The transition is much smoother now.

                One more question please, my first window is a loading screen like the one shown in the picture attached, and then the software windows themselves are in the QStackedWidget.

                In many other software, while the loading screen is showing, the software icon doesn't actually appear in the taskbar, instead it only appears once the actual software has started (The QStackedWidget in my case).
                Do you happen to know how to hide the icon from the taskbar while showing my loading screen (which is a QMainWindow btw) and then showing it later on?
                Thanks a lot.

                icepak-launch-workbench.3ea599da.png

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Ahmed-Zeid Take a look at https://stackoverflow.com/questions/4055506/qt-hide-taskbar-item

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • B Offline
                  B Offline
                  Bonnie
                  wrote on last edited by
                  #7

                  I think loading screen should be separated from other windows.
                  Are you aware that there is a QSplashScreen class?
                  https://doc.qt.io/qt-5/qsplashscreen.html

                  A 1 Reply Last reply
                  4
                  • B Bonnie

                    I think loading screen should be separated from other windows.
                    Are you aware that there is a QSplashScreen class?
                    https://doc.qt.io/qt-5/qsplashscreen.html

                    A Offline
                    A Offline
                    Ahmed Zeid
                    wrote on last edited by
                    #8

                    Hey @Bonnie, I did not know of this class. I started reading about it, and I believe that this would be better for my software. Here's another useful example for PyQt5 if someone is interested:
                    https://stackoverflow.com/questions/58661539/create-splash-screen-in-pyqt5

                    Quick question though, I am planing on building my loading screen (QSplashScreen) on MainWindow1 and then have the rest of my windows in QStackedWidget built on MainWindow2. I have read in an article that using multiple Mainwindows in your software is bad practice. Is this correct? or I can just go forward with my plan?

                    B JonBJ 2 Replies Last reply
                    0
                    • A Ahmed Zeid

                      Hey @Bonnie, I did not know of this class. I started reading about it, and I believe that this would be better for my software. Here's another useful example for PyQt5 if someone is interested:
                      https://stackoverflow.com/questions/58661539/create-splash-screen-in-pyqt5

                      Quick question though, I am planing on building my loading screen (QSplashScreen) on MainWindow1 and then have the rest of my windows in QStackedWidget built on MainWindow2. I have read in an article that using multiple Mainwindows in your software is bad practice. Is this correct? or I can just go forward with my plan?

                      B Offline
                      B Offline
                      Bonnie
                      wrote on last edited by Bonnie
                      #9

                      @Ahmed-Zeid said in Facing problems with switching through multiple windows in my GUI:

                      using multiple Mainwindows in your software is bad practice. Is this correct?

                      In my opinion, yes.
                      Don't put QSplashScreen in any window. Itself is a window, just without title bar / window frame / taskbar item.

                      1 Reply Last reply
                      4
                      • A Ahmed Zeid

                        Hey @Bonnie, I did not know of this class. I started reading about it, and I believe that this would be better for my software. Here's another useful example for PyQt5 if someone is interested:
                        https://stackoverflow.com/questions/58661539/create-splash-screen-in-pyqt5

                        Quick question though, I am planing on building my loading screen (QSplashScreen) on MainWindow1 and then have the rest of my windows in QStackedWidget built on MainWindow2. I have read in an article that using multiple Mainwindows in your software is bad practice. Is this correct? or I can just go forward with my plan?

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #10

                        @Ahmed-Zeid
                        You should only need one main window. (Splash screen is outside of main window, as @Bonnie said.)

                        and then have the rest of my windows in QStackedWidget built on MainWindow2

                        What do you mean by "built on"? Your main window should have a QStackedWidget as its main/central widget, and then your various "pages" should just be QWidgets placed in the stacked widget, not QMainWindows themselves. The main window's framework is around the outside of the stacked widget.

                        A 1 Reply Last reply
                        2
                        • JonBJ JonB

                          @Ahmed-Zeid
                          You should only need one main window. (Splash screen is outside of main window, as @Bonnie said.)

                          and then have the rest of my windows in QStackedWidget built on MainWindow2

                          What do you mean by "built on"? Your main window should have a QStackedWidget as its main/central widget, and then your various "pages" should just be QWidgets placed in the stacked widget, not QMainWindows themselves. The main window's framework is around the outside of the stacked widget.

                          A Offline
                          A Offline
                          Ahmed Zeid
                          wrote on last edited by
                          #11

                          Hello, @JonB, thanks a lot for your reply. Yes, this is exactly what I meant.
                          Sorry for being unclear before.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved