In this PyQt5 article, we want to learn How to Customize the Appearance of PyQt5 Application, so PyQt5 is a powerful Python GUI framework for building desktop applications. even though PyQt5 has a lot of widgets for building nice and powerful look and feel, but sometimes you may want to customize the appearance of your PyQt5 application. in this article, we want to talk about different techniques and options to help you create nice and wonderful user interfaces.
How to Change PyQt5 Window Title and Icon
The first step in customizing your GUI application in PyQt5 is to change the window title and icon. You can do this by using setWindowTitle() and setWindowIcon() methods of the QMainWindow class like this.
1 2 |
self.setWindowTitle("My Custom App") self.setWindowIcon(QIcon("icon.png")) |
How to Customize Fonts and Colors in PyQt5
PyQt5 provides several ways to modify fonts and colors throughout your application. you can use setFont() method to set a custom font for specific widgets or even the entire application. and also setStyleSheet() method allows you to define custom CSS like stylesheets to control the appearance of different widgets.
1 2 3 4 5 6 7 |
# Setting custom font for QLabel label = QLabel("Hello, PyQt5!") font = QFont("Arial", 12) label.setFont(font) # Applying custom stylesheet to widget widget.setStyleSheet("background-color: blue; color: white;") |
How to Create Custom Stylesheet in PyQt5
Stylesheets provide a powerful way to define the visual appearance of your PyQt5 application. you can use CSS like syntax to customize different aspects such as background colors, fonts, borders and many more. By applying stylesheets to individual widgets or entire layouts, you can achieve a unique design. this is an example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Creating custom stylesheet for QPushButton button_style = """ QPushButton { background-color: red; color: white; font-size: 16px; padding: 10px; } QPushButton:hover { background-color: darkred; } """ button = QPushButton("Click me") button.setStyleSheet(button_style) |
PyQt5 Customizing Icons
Icons play a vital role in the visual appeal of an application. PyQt5 provides support for different types of icons, including standard system icons, custom images and SVG icons. you can set icons for buttons, menus or even the application window using the setIcon() method. you can also use the QIcon class to load and manipulate icons dynamically.
1 2 3 4 5 |
# Setting an icon for QPushButton button.setIcon(QIcon("path/to/icon.png")) # Loading an SVG icon and setting it for QAction action = QAction(QIcon("icon.svg"), "Action", self) |
PyQt5 Custom Graphics and Effects
PyQt5 allows you to leverage its powerful graphics framework to create custom visuals for your application. you can subclass QWidget or QFrame and override the paintEvent() method to draw custom shapes, images or apply different effects. this gives you complete control over the appearance of your application.
1 2 3 4 5 6 7 8 |
class CustomWidget(QWidget): def paintEvent(self, event): painter = QPainter(self) #Perform painting operations using QPainter methods # Creat custom widget and adding it to the application layout custom_widget = CustomWidget() layout.addWidget(custom_widget) |
This is the complete code for this article
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QVBoxLayout, QWidget from PyQt5.QtGui import QIcon, QFont, QPainter from PyQt5.QtCore import Qt class CustomMainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("My Custom App") self.setWindowIcon(QIcon("icon.png")) central_widget = QWidget(self) self.setCentralWidget(central_widget) layout = QVBoxLayout(central_widget) label = QLabel("Hello Geekscoders.com") font = QFont("Arial", 12) label.setFont(font) layout.addWidget(label) button_style = """ QPushButton { background-color: red; color: white; font-size: 16px; padding: 10px; } QPushButton:hover { background-color: darkred; } """ button = QPushButton("Click me") button.setStyleSheet(button_style) layout.addWidget(button) custom_widget = CustomWidget() layout.addWidget(custom_widget) class CustomWidget(QWidget): def paintEvent(self, event): painter = QPainter(self) painter.setPen(Qt.red) painter.setBrush(Qt.yellow) painter.drawRect(50, 50, 200, 100) if __name__ == "__main__": app = QApplication(sys.argv) window = CustomMainWindow() window.show() sys.exit(app.exec_()) |
Run your code and this will be the output

Learn More
- PyQt5 Introduction & Installation
- Working with Web Content with PyQt5
- Working with Tables and Models in PyQt5
- How to Create ComboBox in PyQt5
- How to Create List Box in PyQt5
- How to Create QPushButton in PyQt5
- How to Add Text and Image in PyQt5