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 :