Tuesday, October 7, 2025
HomeLanguagesPyQt5 – Different border size for each side in Label

PyQt5 – Different border size for each side in Label

In this article we will see how to set different border size to the label, by default there is no border set to the label although we can add border to the label with the help of setting border using style sheet but that border is uniform and have same size for all the four sides.

Below is the representation of normal bordered label vs the label with different border sizes.

Syntax :




label.setStyleSheet("border : solid black;"
     "border-width : 10px 1px 10px 1px;")


Explanation : border-width is used to set the thickness first element refer to the thickness of upper side, second element refer to the right side, third element refer to the bottom side and fourth element refer to the left side.

Below is the implementation.




# importing the required libraries
  
from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
  
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
        # set the title
        self.setWindowTitle("Python")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # creating a label widget
        self.label_1 = QLabel("Label ", self)
  
        # setting up the border with different size
        self.label_1.setStyleSheet("border : solid black;"
                                   "border-width : 10px 1px 10px 1px;")
  
        # resizing the label
        self.label_1.resize(100, 40)
  
        # moving the label
        self.label_1.move(100, 100)
  
        # show all the widgets
        self.update()
        self.show()
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS