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. MainWindow GUI not refreshing/animating, buttons work ok. Pyside 6

MainWindow GUI not refreshing/animating, buttons work ok. Pyside 6

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 458 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.
  • J Offline
    J Offline
    Julian Ragan
    wrote on last edited by
    #1

    Hello!

    I have built my UI using Qt Designer, and when I use QUiLoader to load it, it works fine, but after I tried to switch to class to overload window closing event, the UI became somewhat non responsive, QEditLine does not show string set with setText() and push buttons are not animated (although I can click them and show file pickers or run configuration dialog, which works fine).

    Originally I was using this code to run UI (and it worked fine, but without closing event) :

    def showGUI():
        app = QApplication(sys.argv)
    
        ui_file_name = "interface\\mainwindow.ui"
        ui_file = QFile(ui_file_name)
        if not ui_file.open(QIODevice.ReadOnly):
            print(f"Cannot open {ui_file_name}: {ui_file.errorString()}")
            sys.exit(-1)
        loader = QUiLoader()
        window = loader.load(ui_file)
        cont = Controller(window)
        window.btnFile.clicked.connect(cont.selectFile)
        window.btnDirectory.clicked.connect(cont.selectDirectory)
        window.btnReportDir.clicked.connect(cont.selectReportDirectory)
        window.ckbPreview.stateChanged.connect(cont.showPreview)
        window.btnRecognize.clicked.connect(cont.recognize)
        window.btnDialog.clicked.connect(cont.showDialog)
        ui_file.close()
        if not window:
            print(loader.errorString())
            sys.exit(-1)
        window.show()
        sys.exit(app.exec_())
    

    But I have redesigned it to work like this:

    def showGUI2():
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        app.processEvents()
        sys.exit(app.exec_())
    
    class MainWindow(QMainWindow):
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            ui_file_name = "interface\\mainwindow.ui"
            ui_file = QFile(ui_file_name)
            if not ui_file.open(QIODevice.ReadOnly):
                print(f"Cannot open {ui_file_name}: {ui_file.errorString()}")
                sys.exit(-1)
            loader = QUiLoader()
            if (parent):
                self.ui = loader.load(ui_file, parent)
            else:
                self.ui = loader.load(ui_file)
            ui_file.close()
            self.cont = Controller(self.ui)
            self.ui.btnFile.clicked.connect(self.cont.selectFile)
            self.ui.btnDirectory.clicked.connect(self.cont.selectDirectory)
            self.ui.btnReportDir.clicked.connect(self.cont.selectReportDirectory)
            self.ui.ckbPreview.stateChanged.connect(self.cont.showPreview)
            self.ui.btnRecognize.clicked.connect(self.cont.recognize)
            self.ui.btnDialog.clicked.connect(self.cont.showDialog)
            self.ui.installEventFilter(self)
    
        def eventFilter(self, watched, event) -> bool:
            if event.type() == PySide6.QtCore.QEvent.Close:
                self.closeEvent(event)
            return True
    
        def show(self) -> None:
            self.ui.show()
    
        def closeEvent(self, event):
            reply = QMessageBox.question(self, 'Confirm quit',
                                         "Do you really want to quit?", QMessageBox.Yes, QMessageBox.No)
            if reply == QMessageBox.Yes:
                config.Configuration.getInstance().storeConfiguration()
                event.accept()
            else:
                event.ignore()
    

    Any ideas as to what I did wrong with initialization of my UI in the class? I normally do Java, so Python is not my stron suit.
    I am using pyside 6.0.1 and python 3.7

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

      Hi and welcome to devnet,

      You don't show your self.ui widget.

      Since you decided to use it in a QMainWindow, you should set it as central widget.

      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
      1
      • J Offline
        J Offline
        Julian Ragan
        wrote on last edited by
        #3

        Thank you.

        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