PDA

View Full Version : PyQT5 No Taskbar Details after Splash Screen



JimKarvo
7th November 2019, 12:26
Hello,

I know this is a QT Forum and no specified PyQT / Python forum
But The problem I face maybe is "so easy" but I can't see the solution

I have this Python Code.

First I open an QMainWindow as Splash Screen, while I load the settings, customers, sales etc..

But When I close the Splash Screen, and open the Main Screen, the taskbar details disappeared!

This is the code:



from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType
import os
import sys
import time



class ThreadProgress(QThread):
mysignal = pyqtSignal(int, str)

def __init__(self, parent=None):
QThread.__init__(self, parent)

def run(self):
i = 0
while i < 102:
time.sleep(0.02)
self.mysignal.emit(i, "txt")
i += 1


FROM_SPLASH, _ = loadUiType(os.path.join(os.path.dirname(__file__), "splash.ui"))
FROM_MAIN, _ = loadUiType(os.path.join(os.path.dirname(__file__), "mainwindow FRAME.ui"))


class Main(QMainWindow, FROM_MAIN):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)


class Splash(QMainWindow, FROM_SPLASH):
def __init__(self, parent=None):
super(Splash, self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)

pixmap = QPixmap("splash_logo.png")
self.splah_image.setPixmap(pixmap.scaled(350, 152))

progress = ThreadProgress(self)
progress.mysignal.connect(self.progress)
progress.start()

@pyqtSlot(int, str)
def progress(self, i, txt):
if i == 101:
self.close()
self.setStyleSheet("")
main = Main(self)
main.show()
self.progressBar.setValue(i)
self.SubText.setText(txt)



def main():
app = QApplication(sys.argv)
splash = Splash()
splash.show()

app.exec_()


if __name__ == '__main__':
try:
main()
except Exception as why:
print(why)


Can you suggest me a solution?

Thank you very much

d_stranz
7th November 2019, 19:27
I don't understand why you are using QMainWindow for the splash screen when Qt has a QSplashScreen class for this purpose. I also don't understand why you are using calls to sleep() instead of using a single-shot QTimer to control the length of time the splash screen is displayed.

The usual scenario is:

- Create the QSplashScreen instance
- Create the QMainWindow instance. Do not call show() on it.
- Tell the splash screen that it should close when the main window is shown (QSplashScreen::finish())
- show() the splash screen
- Create a single-shot QTimer and connect its timeout() signal to the main window's show() slot, then start the timer.
- app.exec_()

If loading the background data is time consuming, then instead of using a QTimer, have the data loading method call show() on the main window when it finishes. That way, the splash screen will be displayed for as long as it takes to complete loading your data.