I have the following simple app setup. Presently the top half of the screen has 3 widgets representing where I will fill in my data later. The yellow section needs to be larger than the red and purple sections. How do I achieve this and how can I maintain the scale when resizing the window? I would like the red and purple sections to take up about 30% each and the yellow portion to take up the center 40%.
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys
class Color(QWidget):
def __init__(self, color):
super(Color, self).__init__()
self.setAutoFillBackground(True)
self.color = color
palette = self.palette()
palette.setColor(QPalette.Window, QColor(self.color))
self.setPalette(palette)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("My App")
self.setMinimumWidth(600)
self.setMinimumHeight(400)
main_div = QVBoxLayout()
main_div.setContentsMargins(0,0,0,0)
main_div.setSpacing(0)
layout2 = QHBoxLayout()
layout2.addWidget(Color('red'))
layout2.addWidget(Color('yellow'))
layout2.addWidget(Color('purple'))
main_div.addLayout( layout2 )
main_div.addWidget(Color('blue'))
self.widget = QWidget()
self.widget.setLayout(main_div)
self.setCentralWidget(self.widget)
def resizeEvent(self,event):
pass
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()