Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.

License

NotificationsYou must be signed in to change notification settings

yjg30737/pyqt-translucent-full-loading-screen-thread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.

Requirements

PyQt5 >= 5.8

Setup

pip3 install git+https://github.com/yjg30737/pyqt-translucent-full-loading-screen-thread.git --upgrade

Usage

This package mainly consists of two classes.LoadingTranslucentScreen(parent: QWidget, description_text: str = '', dot_animation: bool = True) andLoadingThread(loading_screen: LoadingTranslucentScreen). I can show you how it works basically.

self.loadingTranslucentScreen=LoadingTranslucentScreen(parent=self,description_text='Waiting...',dot_animation=False)self.thread=LoadingThread(loading_screen=self.loadingTranslucentScreen)self.thread.start()

Just give the parent widget toLoadingTranslucentScreen as afirst argument.

Second argument is description text ofQLabel which will be shown with loading icon(loading icon is .gif extension,QMovie will get the gif loading icon) when you start theLoadingThread. Defaut value is empty string.

Third argument(dot_animation) decides if triple dots animation of description text will operate or not. There is an explanation of triple dots animation feature below. Default value is True.

Give instant ofLoadingTranslucentScreen toLoadingThread's argument and call the start method of it.

Defaultrun() task of this thread istime.sleep(5).

You can inherit this module and override run method.

You can usesetDescriptionLabelDirection(direction: str) method ofLoadingTranslucentScreen to set the direction of description label.

If thread starts running, dot animation will be activated. If the description text is 'Waiting', dot animation will be like below.

Waiting.Waiting..Waiting...

Of course this feature can reveal a couple of potential flaws if any dots are included in description text. I will fix that soon enough.

Valid argument isLeft,Right,Top,Bottom. All of them should bestr type.

Default direction isBottom.

I show you how to use the methodsetDescriptionLabelDirection.

self.loadingTranslucentScreen.setDescriptionLabelDirection('Right')

If you set the description label direction right like the example above, description text will be shown on the right side of the loading icon.

If you want to show loading icon only, make instance like this.

self.__loadingTranslucentScreen=LoadingTranslucentScreen(parent=self,dot_animation=False)

Example

Code Sample

importtimefromPyQt5.QtWidgetsimportQPushButton,QTextEdit,QVBoxLayout,QWidget,QApplicationfrompyqt_translucent_full_loading_screen_threadimportLoadingThread,LoadingTranslucentScreen# for second resultclassMyThread(LoadingThread):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)defrun(self):time.sleep(1)classMain(QWidget):def__init__(self):super().__init__()self.__initUi()def__initUi(self):btn=QPushButton('Start Loading Thread')btn.clicked.connect(self.__startLoadingThread)self.__te=QTextEdit()lay=QVBoxLayout()lay.addWidget(btn)lay.addWidget(self.__te)self.setLayout(lay)def__startLoadingThread(self):self.__loadingTranslucentScreen=LoadingTranslucentScreen(parent=self,description_text='Waiting')self.__loadingTranslucentScreen.setDescriptionLabelDirection('Right')self.__thread=LoadingThread(loading_screen=self.__loadingTranslucentScreen)# for second result# self.__thread = MyThread(loading_screen=self.__loadingTranslucentScreen)self.__thread.start()if__name__=='__main__':importsysapp=QApplication(sys.argv)window=Main()window.show()app.exec()

Result

1. Result ofLoadingThread which is module itself

example1.mp4

Loading screen is shown for 5 seconds.

2. Result ofMyThread which inherits theLoadingThread

example2.mp4

Loading screen is shown for 1 second. Becauserun() method ofMyThread overridesLoadingThread's.

About

PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp