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. Changing from Main Window to a new Window

Changing from Main Window to a new Window

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 411 Views
  • 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
    Starstriker
    wrote on last edited by
    #1

    Hello,
    i have some problems with my code. Im trying to change from a main window to new window.
    Here is the code:

    import sys
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtCore import Qt
    from Tempauslesen_Test import Temperatur1
    from PyQt5.QtCore import QTimer
    
    class do_Progressbar(QMainWindow):
            def setupUi(self, MainWindow):
                MainWindow.setObjectName("MainWindow")
                MainWindow.resize(300, 300)
                self.centralwidget = QtWidgets.QWidget(MainWindow)
                self.centralwidget.setObjectName("centralwidget")
                self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
                self.progressBar.setGeometry(QtCore.QRect(80, 120, 118, 24))
                self.progressBar.setMaximum(200)
                #self.progressBar.setProperty(0)
                self.progressBar.setObjectName("progressBar")
                MainWindow.setCentralWidget(self.centralwidget)
                self.menubar = QtWidgets.QMenuBar(MainWindow)
                self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 28))
                self.menubar.setObjectName("menubar")
                MainWindow.setMenuBar(self.menubar)
                self.statusbar = QtWidgets.QStatusBar(MainWindow)
                self.statusbar.setObjectName("statusbar")
                MainWindow.setStatusBar(self.statusbar)
    
                self.retranslateUi(MainWindow)
                QtCore.QMetaObject.connectSlotsByName(MainWindow)
            
                self.timer = QTimer()
                self.timer.timeout.connect(self.update_temperature)
                self.timer.start(1)
    
            def update_temperature(self):
                temperature = Temperatur1()
                if temperature < 500:
                    self.progressBar.setValue(temperature)
                else:
                    self.timer.stop()
    
            def retranslateUi(self, MainWindow):
                _translate = QtCore.QCoreApplication.translate
                MainWindow.setWindowTitle(_translate("MainWindow", "Temperatur1"))
                self.progressBar.setFormat(_translate("MainWindow", "%p°C"))
    
           
    class Fenster(QWidget):  												
    
        def __init__(self):													
            super(Fenster,self).__init__()	
            self.initMe()												
    
        def initMe(self):
            button1 = QPushButton('Abfahrt!',self)
            button1.move(300,300)
            button1.clicked.connect(self.do_progressbar1)
            button2 = QPushButton('Abbrechen',self)
            button2.move(400,300)
            button2.clicked.connect(QtCore.QCoreApplication.instance().quit)					
            w = QLabel(self)
            w.setPixmap(QPixmap("Download.png"))
            w.move(200,50)
            z = QLabel("<html><head/><body><p><span style=\" font-size:9pt; font-style:italic;\">Copyright by Felix Horstmann, Kevin Weidner</span></p></body></html>",self)
            z.move(50,400)
            self.setGeometry(50,50,790,435)								
            self.setWindowTitle("Rotor-Heizprozess")						
            self.setWindowIcon(QIcon("Feuer.png"))							
            self.show() 
            
        def do_progressbar1(self):
            self.w = do_Progressbar()
            self.w.show()
            self.hide()
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        w = Fenster()															
        sys.exit(app.exec_())													
    
    

    This code is running, but after clicking on the button, only an empty window is opening.
    Any ideas?

    greetz from Germany

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

      Hi and welcome to devnet,

      One thing that stands out is that you re-implement setupUi which won't be called if you don't do it in the constructor and that method is used for Designer based widget.

      However, shouldn't you rather use a QDialog rather than a full blown QMainWindow to show a progress bar ?

      It will also make your code simpler and cleaner.

      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

      • Login

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