Search code examples
pythonpyqtpyqt5window-resize

how can i create resizable widgets in PyQt5?


i am working on a project using PyQt5 and i want to make sure that the widgets are resizable by the user >

what do i mean ?

this is a picture explains the meaning :

enter image description here

i want to make the user be able to resize each widget or make the left bigger the the right by his mouse control

i am very sorry because i do not know how to write a code make you close to the result , because i am not close at all ... but i wrote a code to try on :


from PyQt5 import QtWidgets
import sys


app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.resize(800,500)
window_layout = QtWidgets.QGridLayout()



first_widget = QtWidgets.QGroupBox()
first_widget.setStyleSheet("background-color:rgb(0,150,0)")



second_widget = QtWidgets.QGroupBox()
second_widget.setStyleSheet("background-color:rgb(150,0,0)")



window_layout.addWidget(first_widget,0,0)
window_layout.addWidget(second_widget,0,1)
window.setLayout(window_layout)
window.show()
app.exec()

thanks


Solution

  • this is the answer to my question.

    but first i want to thank mahkitah user whom help me to find the solution.

    here is my code.

    from PyQt5 import QtWidgets
    import sys
    
    
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QWidget()
    window.resize(800,500)
    window_layout = QtWidgets.QGridLayout()
    
    
    
    first_widget = QtWidgets.QGroupBox()
    first_widget.setStyleSheet("background-color:rgb(0,150,0)")
    
    
    
    second_widget = QtWidgets.QGroupBox()
    second_widget.setStyleSheet("background-color:rgb(150,0,0)")
    
    
    
    splitter = QtWidgets.QSplitter()
    splitter.addWidget(first_widget)
    splitter.addWidget(second_widget)
    
    
    window_layout.addWidget(splitter)
    window.setLayout(window_layout)
    window.show()
    app.exec()