PyQt5 – Set maximum window size
Last Updated :
26 Mar, 2020
When we create a window, by default, it is resizable but with the help of setFixedSize()
method we can fix the size of window. But what if we want to resize the window up-to some extent; in order to do this, we have to set the maximum size of the window. We will use setMaximumSize()
method.
Syntax : self.setMaximumSize(width, height)
Argument : It takes two argument both integer i.e width and height.
Action performed : It set the maximum size of window.
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" )
width = 500
height = 400
self .setMaximumSize(width, height)
self .label_1 = QLabel( "Maximum size" , self )
self .label_1.move( 0 , 0 )
self .label_1.setStyleSheet( "border :3px solid black;" )
self .label_1.resize( 120 , 80 )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...