PyQt5 – How to change border style of MainWindow ?
Last Updated :
26 Mar, 2020
When we create a window in PyQt5, by default, there is no special type of border to it. But we change the style, thickness as well as color of the main window by using setStyleSheet()
method.
Below is how normal border vs styled border looks like
Syntax : self.setStyleSheet(“border : 3px dashed blue;”)
Argument: It takes string as argument.
"border : size_of_border type_of_border color_of_border;"
Action performed : It sets the border style.
Code :
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 .setStyleSheet( "border : 3px dashed blue;" )
self .label_1 = QLabel( "new border " , self )
self .label_1.move( 100 , 100 )
self .label_1.setStyleSheet( "border :3px solid black;" )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...