Thursday, February 5, 2026
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
32479 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11980 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6988 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6936 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS