Search code examples
pythonpython-3.xpyside2

How do I change the MainWindow Title in Python when using Form()?


I am trying to change the title of the window applications but I don't see how to do it for my specific case where I am loading the *.ui file as a form.

A simplified version of my code so far looks like so:

import sys, os
from sys import stdout, stdin, stderr
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit, QTextBrowser
from PySide2.QtCore import QFile, QObject, QEvent 

class Form(QObject):

    def __init__(self, ui_file, parent=None):
        super(Form, self).__init__(parent)
        ui_file = QFile(ui_file)
        ui_file.open(QFile.ReadOnly)

        loader = QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()

        self.window.show()


if __name__ == '__main__':
        print("Starting up tool application...\nPlease wait.")
        app = QApplication(sys.argv)
        form = Form('mifareclassictool.ui')
        sys.exit(app.exec_())

I tried self.setWindowTitle("title") within the Form class but that property does not exist. I am still new to Qt Designer and creating applications in python.


Solution

  • The form is not the window so you can not use self.setWindowTitle("title"), instead you should use self.window:

    self.window.setWindowTitle("title")