Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Show a Loading Home Dialog before starting MainWindow
Forum Updated to NodeBB v4.3 + New Features

Show a Loading Home Dialog before starting MainWindow

Scheduled Pinned Locked Moved Solved Qt for Python
30 Posts 4 Posters 5.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 28 Jan 2021, 18:16 last edited by
    #2

    Hi,

    It looks a bit like a "mini-wizard" so you could use a QWizard for that.

    Not that if you have a long running operation, you might want to use QtConcurrent::run to execute it and let the GUI show a QProgressBar or a QProgressDialog depending on the road you take.

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

    1 Reply Last reply
    2
    • H Offline
      H Offline
      hachbani
      wrote on 29 Jan 2021, 11:22 last edited by
      #3

      Hi @SGaist ,

      I've been looking at QWizard, not sure if this is what i'm looking for, in addition to that, I gave it a try but struggling hard to implement it. Is there now other classes I can use ?

      J 1 Reply Last reply 29 Jan 2021, 11:27
      0
      • H hachbani
        29 Jan 2021, 11:22

        Hi @SGaist ,

        I've been looking at QWizard, not sure if this is what i'm looking for, in addition to that, I gave it a try but struggling hard to implement it. Is there now other classes I can use ?

        J Offline
        J Offline
        JonB
        wrote on 29 Jan 2021, 11:27 last edited by
        #4

        @hachbani
        Look at the QProgressBar/QProgressDialog alternative approach @SGaist suggested. That is the usual way to show the user when a background operation is running.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hachbani
          wrote on 29 Jan 2021, 12:14 last edited by
          #5

          @JonB

          i've looking into QProgressDialog, the progressDialog is shown but not updated. From what I saw on several forums posts: do I have to use a QThread as well ?

          Here's my code:

          class progressBar(QtWidgets.QProgressDialog):
              def __init__(self, parent= None):
                  super(progressBar, self).__init__(parent)
                  pd = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
          
          class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
              def __init__(self, parent=None):
                  """
                  ..
                  __init__ code lines
                  """
                  self.hide()
                  d = HomeDialog()
                  if d.exec_():
                      self.LoadData(d.path)
          
              def LoadData(self, file_path):
                  progress = progressBar()
                  progress.show()
                  progress.setValue(1)
                  """
                  Parsing lines of code
                  progress.setValue(30)
                  ..
                  ..
                  progress.setValue(70)
                  ..
                  ..
                  """
                  progress.hide()
                  #Parsing finished -> show the mainWindow
                  self.show()
          
          class HomeDialog(QtWidgets.QDialog, home_dialog.Ui_Dialog):
              def __init__(self, parent=None):
                  super(HomeDialog, self).__init__(parent)
                  self.setupUi(self)
                  self.openB6.clicked.connect(self.get_file_name)
          
              def get_file_name(self):
                  file_name = QtWidgets.QFileDialog.getOpenFileName(self, 'Open config file',
                                                                      dir=path.join("/"),
                                                                      filter="B6 (*.b6)")
                  if not file_name[0]:
                      return None
                  else:
                      self.path = file_name
                      self.accept()
          
          if __name__ == '__main__':
              app = QtWidgets.QApplication(sys.argv)
              app.setStyle(ProxyStyle())
              mainWin = MainWindow()
              mainWin.show()
              sys.exit(app.exec_())
          
          J 1 Reply Last reply 29 Jan 2021, 12:17
          0
          • H hachbani
            29 Jan 2021, 12:14

            @JonB

            i've looking into QProgressDialog, the progressDialog is shown but not updated. From what I saw on several forums posts: do I have to use a QThread as well ?

            Here's my code:

            class progressBar(QtWidgets.QProgressDialog):
                def __init__(self, parent= None):
                    super(progressBar, self).__init__(parent)
                    pd = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
            
            class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
                def __init__(self, parent=None):
                    """
                    ..
                    __init__ code lines
                    """
                    self.hide()
                    d = HomeDialog()
                    if d.exec_():
                        self.LoadData(d.path)
            
                def LoadData(self, file_path):
                    progress = progressBar()
                    progress.show()
                    progress.setValue(1)
                    """
                    Parsing lines of code
                    progress.setValue(30)
                    ..
                    ..
                    progress.setValue(70)
                    ..
                    ..
                    """
                    progress.hide()
                    #Parsing finished -> show the mainWindow
                    self.show()
            
            class HomeDialog(QtWidgets.QDialog, home_dialog.Ui_Dialog):
                def __init__(self, parent=None):
                    super(HomeDialog, self).__init__(parent)
                    self.setupUi(self)
                    self.openB6.clicked.connect(self.get_file_name)
            
                def get_file_name(self):
                    file_name = QtWidgets.QFileDialog.getOpenFileName(self, 'Open config file',
                                                                        dir=path.join("/"),
                                                                        filter="B6 (*.b6)")
                    if not file_name[0]:
                        return None
                    else:
                        self.path = file_name
                        self.accept()
            
            if __name__ == '__main__':
                app = QtWidgets.QApplication(sys.argv)
                app.setStyle(ProxyStyle())
                mainWin = MainWindow()
                mainWin.show()
                sys.exit(app.exec_())
            
            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 29 Jan 2021, 12:17 last edited by jsulm
            #6

            @hachbani said in Show a Loading Home Dialog before starting MainWindow:

            class progressBar(QtWidgets.QProgressDialog):
            def init(self, parent= None):
            super(progressBar, self).init(parent)
            pd = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)

            Why do you create an instance of QtWidgets.QProgressDialog in progressBar which is already itself a QtWidgets.QProgressDialog?!

            "do I have to use a QThread as well ?" - depends on how you process.

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

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hachbani
              wrote on 29 Jan 2021, 12:19 last edited by
              #7

              To be honest I don't really know, for aesthetic reasons I guess, I've tried without creating the class (pd=QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self) ) in the LoadData function. I get the same result

              J 2 Replies Last reply 29 Jan 2021, 12:21
              0
              • H hachbani
                29 Jan 2021, 12:19

                To be honest I don't really know, for aesthetic reasons I guess, I've tried without creating the class (pd=QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self) ) in the LoadData function. I get the same result

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 29 Jan 2021, 12:21 last edited by jsulm
                #8

                @hachbani said in Show a Loading Home Dialog before starting MainWindow:

                for aesthetic reasons I guess

                Aesthetic reasons? There is absolutely no need for this pd - you are basically creating TWO progress dialogs (but only show one).
                Why it does not work: well, you do not show how you process the data after showing progress dialog...

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

                1 Reply Last reply
                0
                • H hachbani
                  29 Jan 2021, 12:19

                  To be honest I don't really know, for aesthetic reasons I guess, I've tried without creating the class (pd=QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self) ) in the LoadData function. I get the same result

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 29 Jan 2021, 12:24 last edited by
                  #9

                  @hachbani Basic approach is: show progress dialog, start your long lasting operation, on each iteration emit a signal which is connected to https://doc.qt.io/qt-5/qprogressdialog.html#value-prop slot.

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

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hachbani
                    wrote on 29 Jan 2021, 13:58 last edited by hachbani
                    #10

                    I updated the code a follow:

                    created a signal: self.change_val = QtCore.Signal(int) and connected it to a slot set_progress_val

                    in the LoadData, I emit change_val signal at different places.

                    Also did some changes in the if name == 'main'

                    
                    class MainWindow(QtWidgets.QMainWindow,  Ui_MainWindow):
                    
                        change_val = QtCore.Signal(int)
                        def __init__(self, file_name,parent=None):
                            """
                            super(MainWindow, self).__init__(parent)
                            ..
                            __init__ code lines
                            """
                    
                            change_val.connect(self.set_progress_val)
                            self.progress = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
                            self.progress.show()
                            self.LoadData(d.path)
                        
                        @QtCore.Slot(int)
                        def set_progress_val(self, val):
                            self.progress.setValue(val)
                    
                        def LoadData(self, file_path):
                            
                            """
                            Parsing lines of code
                            ..
                            change_val.emit(30)
                            ..
                            ..
                            change_val.emit(60)
                            ..
                            ..
                            """
                            self.progress.hide()
                            #Parsing finished -> show the mainWindow
                            self.show()
                    
                    class HomeDialog(QtWidgets.QDialog, home_dialog.Ui_Dialog):
                        def __init__(self, parent=None):
                            super(HomeDialog, self).__init__(parent)
                            self.setupUi(self)
                            self.openB6.clicked.connect(self.get_file_name)
                    
                        def get_file_name(self):
                            file_name = QtWidgets.QFileDialog.getOpenFileName(self, 'Open config file',
                                                                                dir=path.join("/"),
                                                                                filter="B6 (*.b6)")
                            if not file_name[0]:
                                return None
                            else:
                                self.path = file_name
                                self.accept()
                    
                    if __name__ == '__main__':
                        app = QtWidgets.QApplication(sys.argv)
                        app.setStyle(ProxyStyle())
                        d = HomeDialog()
                        if d.exec_():
                            mainWin = MainWindow(file_name=d.path)
                            mainWin.show()
                            sys.exit(app.exec_())
                    

                    I get the following error: 'str' object has no attribute 'connect'

                    J 1 Reply Last reply 29 Jan 2021, 14:06
                    0
                    • H hachbani
                      29 Jan 2021, 13:58

                      I updated the code a follow:

                      created a signal: self.change_val = QtCore.Signal(int) and connected it to a slot set_progress_val

                      in the LoadData, I emit change_val signal at different places.

                      Also did some changes in the if name == 'main'

                      
                      class MainWindow(QtWidgets.QMainWindow,  Ui_MainWindow):
                      
                          change_val = QtCore.Signal(int)
                          def __init__(self, file_name,parent=None):
                              """
                              super(MainWindow, self).__init__(parent)
                              ..
                              __init__ code lines
                              """
                      
                              change_val.connect(self.set_progress_val)
                              self.progress = QtWidgets.QProgressDialog('loading...', 'cancel', 0, 100, self)
                              self.progress.show()
                              self.LoadData(d.path)
                          
                          @QtCore.Slot(int)
                          def set_progress_val(self, val):
                              self.progress.setValue(val)
                      
                          def LoadData(self, file_path):
                              
                              """
                              Parsing lines of code
                              ..
                              change_val.emit(30)
                              ..
                              ..
                              change_val.emit(60)
                              ..
                              ..
                              """
                              self.progress.hide()
                              #Parsing finished -> show the mainWindow
                              self.show()
                      
                      class HomeDialog(QtWidgets.QDialog, home_dialog.Ui_Dialog):
                          def __init__(self, parent=None):
                              super(HomeDialog, self).__init__(parent)
                              self.setupUi(self)
                              self.openB6.clicked.connect(self.get_file_name)
                      
                          def get_file_name(self):
                              file_name = QtWidgets.QFileDialog.getOpenFileName(self, 'Open config file',
                                                                                  dir=path.join("/"),
                                                                                  filter="B6 (*.b6)")
                              if not file_name[0]:
                                  return None
                              else:
                                  self.path = file_name
                                  self.accept()
                      
                      if __name__ == '__main__':
                          app = QtWidgets.QApplication(sys.argv)
                          app.setStyle(ProxyStyle())
                          d = HomeDialog()
                          if d.exec_():
                              mainWin = MainWindow(file_name=d.path)
                              mainWin.show()
                              sys.exit(app.exec_())
                      

                      I get the following error: 'str' object has no attribute 'connect'

                      J Offline
                      J Offline
                      JonB
                      wrote on 29 Jan 2021, 14:06 last edited by
                      #11

                      @hachbani
                      On which line? self.change_val[int].connect(self.set_progress_val)? Are you using PyQt5, PySide2, or what?

                      H 1 Reply Last reply 29 Jan 2021, 14:08
                      0
                      • J JonB
                        29 Jan 2021, 14:06

                        @hachbani
                        On which line? self.change_val[int].connect(self.set_progress_val)? Are you using PyQt5, PySide2, or what?

                        H Offline
                        H Offline
                        hachbani
                        wrote on 29 Jan 2021, 14:08 last edited by
                        #12

                        I'm using Pyside2, pyothn 3.8

                        I get the error on the follwoing line mainWin = MainWindow(file_name=d.path)

                        J 1 Reply Last reply 29 Jan 2021, 14:10
                        0
                        • H Offline
                          H Offline
                          hachbani
                          wrote on 29 Jan 2021, 14:09 last edited by
                          #13

                          The idea of self.change_val[int].connect(self.set_progress_val) is that when i'm going to call self.change_val.emit(20), the set_progress_val is called with 20 as argument, maybe I'm implementing this wrong

                          1 Reply Last reply
                          0
                          • H hachbani
                            29 Jan 2021, 14:08

                            I'm using Pyside2, pyothn 3.8

                            I get the error on the follwoing line mainWin = MainWindow(file_name=d.path)

                            J Offline
                            J Offline
                            JonB
                            wrote on 29 Jan 2021, 14:10 last edited by JonB
                            #14

                            @hachbani
                            I'll look into the possible connect() issue in a moment. But

                            I get the error on the follwoing line mainWin = MainWindow(file_name=d.path)

                            mainWin = MainWindow(file_name=d.path)
                            

                            I don't see your MainWindow.init() has a file_name argument?

                            Actually, before I look, could we establish where exactly this error is really coming from? With print() statements/debugger, do you actually get to the self.change_val[int].connect(self.set_progress_val) line at all? Or is the error really that constructor line??

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              hachbani
                              wrote on 29 Jan 2021, 14:12 last edited by hachbani
                              #15

                              Just a pasting mistake, I updated the code in my last comment.

                              if I remove all the progressBar code parts, the program will run successfully, but with nothing being shown while the LoadData function is runnung

                              J 1 Reply Last reply 29 Jan 2021, 14:14
                              0
                              • H hachbani
                                29 Jan 2021, 14:12

                                Just a pasting mistake, I updated the code in my last comment.

                                if I remove all the progressBar code parts, the program will run successfully, but with nothing being shown while the LoadData function is runnung

                                J Offline
                                J Offline
                                JonB
                                wrote on 29 Jan 2021, 14:14 last edited by JonB
                                #16

                                @hachbani

                                class MainWindow(QtWidgets.QMainWindow, file_name, Ui_MainWindow):
                                    def __init__(self, parent=None):
                                

                                How do you manage file_name in the class declaration? How do you not have it in the __init__()? I'm not going to guess if this is in fact not the code you have, that's what pasting is for....

                                1 Reply Last reply
                                0
                                • H Offline
                                  H Offline
                                  hachbani
                                  wrote on 29 Jan 2021, 14:18 last edited by hachbani
                                  #17

                                  @JonB said in Show a Loading Home Dialog before starting MainWindow:

                                  Actually, before I look, could we establish where exactly this error is really coming from? With print() statements/debugger, do you actually get to the self.change_val[int].connect(self.set_progress_val) line at all? Or is the error really that constructor line??

                                  I added a print before and after the connect line, I get the first print and then the 'str' object has no attribute 'connect'

                                  the file_name argument gets passed to LoadData at the end of MainWindow __init__()

                                  J 1 Reply Last reply 29 Jan 2021, 14:23
                                  0
                                  • H hachbani
                                    29 Jan 2021, 14:18

                                    @JonB said in Show a Loading Home Dialog before starting MainWindow:

                                    Actually, before I look, could we establish where exactly this error is really coming from? With print() statements/debugger, do you actually get to the self.change_val[int].connect(self.set_progress_val) line at all? Or is the error really that constructor line??

                                    I added a print before and after the connect line, I get the first print and then the 'str' object has no attribute 'connect'

                                    the file_name argument gets passed to LoadData at the end of MainWindow __init__()

                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 29 Jan 2021, 14:23 last edited by JonB
                                    #18

                                    @hachbani said in Show a Loading Home Dialog before starting MainWindow:

                                    the file_name argument gets passed to LoadData at the end of MainWindow init()

                                    class MainWindow(QtWidgets.QMainWindow, file_name, Ui_MainWindow):

                                    I don't understand. It's not an "argument", is it? You have it in the list of classes from which MainWindow derives?? Unless your knowledge of Python is better than mine.

                                    H 1 Reply Last reply 29 Jan 2021, 14:25
                                    0
                                    • J JonB
                                      29 Jan 2021, 14:23

                                      @hachbani said in Show a Loading Home Dialog before starting MainWindow:

                                      the file_name argument gets passed to LoadData at the end of MainWindow init()

                                      class MainWindow(QtWidgets.QMainWindow, file_name, Ui_MainWindow):

                                      I don't understand. It's not an "argument", is it? You have it in the list of classes from which MainWindow derives?? Unless your knowledge of Python is better than mine.

                                      H Offline
                                      H Offline
                                      hachbani
                                      wrote on 29 Jan 2021, 14:25 last edited by hachbani
                                      #19

                                      Sorry sorry, feel ridiculous, it was a mistake, the file_name is indeed an argument to MainWindow init(). I corrected the code in the comment. It was in init in my code, just a rookie mistake while making the minimalistic code

                                      J 1 Reply Last reply 29 Jan 2021, 14:27
                                      0
                                      • H hachbani
                                        29 Jan 2021, 14:25

                                        Sorry sorry, feel ridiculous, it was a mistake, the file_name is indeed an argument to MainWindow init(). I corrected the code in the comment. It was in init in my code, just a rookie mistake while making the minimalistic code

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 29 Jan 2021, 14:27 last edited by
                                        #20

                                        @hachbani
                                        Please understand, we have to get pasting/correct code right! When you've tried to help in this forum for as much as I have you never know what posters have actually got if it's not accurate, and I have wasted too much time over the years answering questions about user code which is not actually the code! :)

                                        I'll think about your connect() now....

                                        H 1 Reply Last reply 29 Jan 2021, 14:28
                                        0
                                        • J JonB
                                          29 Jan 2021, 14:27

                                          @hachbani
                                          Please understand, we have to get pasting/correct code right! When you've tried to help in this forum for as much as I have you never know what posters have actually got if it's not accurate, and I have wasted too much time over the years answering questions about user code which is not actually the code! :)

                                          I'll think about your connect() now....

                                          H Offline
                                          H Offline
                                          hachbani
                                          wrote on 29 Jan 2021, 14:28 last edited by
                                          #21

                                          Sorry again, I acknowledge that I've been wasting your time for a stupid mistake I've made pasting the code due to a lack of attention.

                                          J 1 Reply Last reply 29 Jan 2021, 15:10
                                          0

                                          11/30

                                          29 Jan 2021, 14:06

                                          • Login

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