Question

import sys
from PyQt4 import QtCore, QtGui, uic


class MainWindow(QtGui.QMainWindow):
     def __init__(self):
         QtGui.QMainWindow.__init__(self)

         self.Dynamic_log = uic.loadUi("Dynamic_log.ui")
         self.Dynamic_log.show()

         self.Main_Window = uic.loadUi("Main_Window.ui")
         self.Main_Window.hide()


         self.Dynamic_log.Continue_Button.clicked.connect(self.Continue2)

     def Continue2(self):

         ***self.Main_Window.addWidget(self.progress_label)***

         self.Main_Window.show()
         self.Dynamic_log.hide()



app = QtGui.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())

The triple asterisk is where I am stuck. This line of code explains what I would like to achieve but returns an error instead. I would like to load .ui files using this method and then still be able to add more tools, progressbars, labels buttons etc ... into Main_Window afterwards.

My reason for wanting the .ui files to load this way that it is easier to layout and make changes

My reason for needing to add custom tools afterwards is because i intend to run threads, the quantity being at a users discretion and duplicate tools must be made to match the number of threads.

Was it helpful?

Solution

After hunting for the answer without any luck, I've solved this myself.

After creating a QVBoxLayout within the pyqt4 Designer file (Main_Window), i was then able to refer to it (refer to its name which in this case is ProgressThreads) the same way you would without using the uic.loadUi import method.

the working code reads as follows,

class MyWindow(QWidget): 
    def __init__(self, *args): 
        QWidget.__init__(self, *args)

        self.Dynamic_log = uic.loadUi("Dynamic_log.ui")
        self.Dynamic_log.show()

        self.Main_Window = uic.loadUi("Main_Window.ui")
        self.Main_Window.hide()


        layout = self.Main_Window.ProgressThreads
        self.progress_label = QLabel(" ")
        layout.addWidget(self.progress_label)
        self.progress_label.setText('0%')




if __name__ == "__main__": 
    app = QtGui.QApplication(sys.argv)
    window = MyWindow() 
    sys.exit(app.exec_())

It was also nessesary to change from a QMainWindow to a QWidget

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top