Skip to content
Related Articles

Related Articles

PyQt5 – QApplication

Improve Article
Save Article
  • Last Updated : 25 Aug, 2021
Improve Article
Save Article

The QApplication class manages the GUI application’s control flow and main settings. It specializes in the QGuiApplication with some functionality needed for QWidget based applications. It handles widget specific initialization, finalization. For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2, or more windows at any given time. For non-QWidget based Qt applications, use QGuiApplication instead, as it does not depend on the QtWidgets library.

We then create a window instance and execute the QApplication object in the event loop using sys.exit(App.exec()) command, below are some useful and frequently methods and property used with the QApplication object.

Syntax: App = QApplication(sys.argv)


  • beep: Sounds the bell, using the default volume and sound. This function is not available in Qt for Embedded Linux
  • setFont: It sets the default font of the PyQt5 Application 
  • aboutQt: Displays a simple message box about Qt. The message includes the version number of Qt being used by the application. 
  • closeAllWindows: Closes all top-level windows. This function is particularly useful for applications with many top-level windows.
  • setAutoSipEnabled: It automatically displays the SIP when entering widgets that accept keyboard input
  • setCursorFlashTime: This method sets the text cursor’s flash (blink) time in milliseconds 
  • setDoubleClickInterval: This method sets the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks


We will create a simple PyQt5 application which produces a beep sound when it gets executed and many properties are set to the QApplication object, below is the implementation


# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 500, 400)
        # calling method
        # showing all the widgets
    # method for components
    def UiComponents(self):
        # creating a push button
        push = QPushButton("Press", self)
        # setting geometry to the push button
        push.setGeometry(100, 100, 120, 40)
        # creating a label
        label = QLabel("GeeksforGeeks", self)
        # setting geometry to the label
        label.setGeometry(100, 160, 200, 50)
        # setting alignment to the label
        # font
        font = QFont("Arial", 12)
        # setting font to the label
        # setting style sheet to the label
                            "border : 2px solid green;"
                            "background : lightgreen;"
        # hiding the label
        # adding action method to the push button
        push.clicked.connect(lambda: do_something())
        # method called by the push button when pressed
        def do_something():
            # unhide the label
# create pyqt5 app
App = QApplication(sys.argv)
# setting cursor flashtime
# setting application object name
# setting application display name
App.setApplicationDisplayName("GfG PyQt5")
# beep sound will occur when application
# is opened
# message displayed about the Qt
# create the instance of our Window
window = Window()
# start the app

When we execute the code firstly the about Qt page will get displayed 

Then our application will get started 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!