1

so i am trying to create a GUI with PyQt5 and i need my GUI to be split like below, numbers are Pixels

enter image description here

I am trying to start specific windows at specific pixel value and keep it that way even if I stretch my window i want windows to stay at specific position and be still the same size. So pretty much windows don't change and don't move

i am trying to use function QSplitter, but i cannot find any option to make it start at specific pixel value and be constant

from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame, 
    QSplitter, QStyleFactory, QApplication)
from PyQt5.QtCore import Qt
import sys

class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):      

        hbox = QHBoxLayout(self)

        topleft = QFrame(self)
        topleft.setFrameShape(QFrame.StyledPanel)

        topright = QFrame(self)
        topright.setFrameShape(QFrame.StyledPanel)

        bottom = QFrame(self)
        bottom.setFrameShape(QFrame.StyledPanel)

        splitter1 = QSplitter(Qt.Horizontal)
        splitter1.addWidget(topleft)
        splitter1.addWidget(topright)

        splitter2 = QSplitter(Qt.Vertical)
        splitter2.addWidget(splitter1)
        splitter2.addWidget(bottom)

        hbox.addWidget(splitter2)
        self.setLayout(hbox)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('QSplitter')
        self.show()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

3

IIUC you want the size and position of the QFrame to be fixed, if it is then you should not use QSplitter but must use move to set the position and setFixedSize to set the size:

from PyQt5 import QtCore, QtWidgets


class Example(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        f1 = self.create_qframe(QtCore.QPoint(10, 10), QtCore.QSize(640, 480))
        f2 = self.create_qframe(QtCore.QPoint(10, 500), QtCore.QSize(640, 480))

        f3 = self.create_qframe(QtCore.QPoint(660, 10), QtCore.QSize(320, 240))
        f4 = self.create_qframe(QtCore.QPoint(990, 10), QtCore.QSize(320, 240))

        f5 = self.create_qframe(QtCore.QPoint(660, 260), QtCore.QSize(320, 230))
        f6 = self.create_qframe(QtCore.QPoint(990, 260), QtCore.QSize(320, 230))

        f7 = self.create_qframe(QtCore.QPoint(660, 500), QtCore.QSize(320, 240))
        f8 = self.create_qframe(QtCore.QPoint(990, 500), QtCore.QSize(320, 240))

        f9 = self.create_qframe(QtCore.QPoint(660, 750), QtCore.QSize(320, 230))
        f10 = self.create_qframe(QtCore.QPoint(990, 750), QtCore.QSize(320, 230))

        self.setMinimumSize(1320, 990)
        # or self.setFixedSize(1320, 990)

    def create_qframe(self, pos, size):
        frame = QtWidgets.QFrame(self, frameShape=QtWidgets.QFrame.StyledPanel)
        frame.move(pos)
        frame.setFixedSize(size)
        return frame


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    app.setStyle("fusion")
    w = Example()
    w.show()
    sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241