0

Given that I have already read many discussions on the subject and that I opted for QUiLoader instead of converting the.ui file to file.py for practicality reasons when writing the code (I use to change widgets a lot with QT Creator 10). Anyway.... this is a summary of the code:

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.loader = QUiLoader()
        self.mainW = self.loader.load(r"../ReTaBo_v2/grafica/mainRTB.ui", None)

        self.mainW.show()

    def infoQTstart(self):
        app.aboutQt()


if __name__ == "__main__":
    app = QApplication([])
    app.beep()
    
    mainW = MainWindow()

    atexit.register(closeApp)

    exit(app.exec())

I have the problem that in QT Creator I have created a slot for an action in the menu connected to the QMainWindow named mainW, a slot named infoQTstart(), but the "def infoQTstart()" function is not executed in the code, and I think this is why I should have it loaded the file.ui not to self.mainW but to the MainWindow instance object ie mainW, but I can't do it.

I also tried doing self.loader.load(...) but if I do self.show() it gives me an empty window, i.e. it wouldn't have loaded the file.ui

Wolverine
  • 11
  • 1
  • Your supposition is correct. Unfortunately, PySide doesn't allow to "set up" the ui file on an existing instance, it can only work using a central widget (creating as a "form" in Designer) and providing the parent argument (`self` instead of `None` you used in `load()`). Take a look at [this answer](https://stackoverflow.com/a/27610822) in order to get a more consistent way to load the UI directly on a subclass. – musicamante Apr 06 '23 at 22:57
  • Thank you for your answer. I saw the solution you indicated to me, but I didn't understand which of the two methods is better for PySide6! For now I'll try the first one. However I'm surprised that there isn't a more "linear" solution, less convoluted, or that the developers haven't found it yet and made a version upGrade. – Wolverine Apr 07 '23 at 07:48
  • There is no absolutely better method, only the one that works well for you. Coming from PyQt (which does the setup automatically instead), I'd prefer the modified QUiLoader. And, yes, it's unknown why they never implemented that in PySide. – musicamante Apr 07 '23 at 18:24

0 Answers0