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.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python" )
self .setGeometry( 100 , 100 , 600 , 400 )
self .label_1 = QLabel( "Label " , self )
self .label_1.setStyleSheet( "border : solid black;"
"border-width : 10px 1px 10px 1px;" )
self .label_1.resize( 100 , 40 )
self .label_1.move( 100 , 100 )
self .update()
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Last Updated :
22 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...