Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to force layout from not going into other layout's area



  • I am trying to create a layout as shown in the image below, however, I am having the issue where the topbar layout is moving into the area that is designated to the middle layout. I have made sure that I specify what percentage the topbar layout is allowed to take up in relation to the right layout. However, it doesn't seem to be stopping it from moving down. So, when I attempt to add widgets in the middle grid, they are being pushed down by the topbar layout as shown in the second image. The searchbar, confirmbutton, and logout text should all be in the blue frame. For some reason, if I add more widgets to the middle layout, it starts pushing the topbar layout up, but this shouldn't be the case and the topbar should already be up no matter how many are added.

    This is what my code looks like for the layouts

     ################### Layouts ###################
            self.mainlayout = QHBoxLayout()
            self.rightlayout = QVBoxLayout()
            self.topbar = QHBoxLayout()
            self.sidebar = QVBoxLayout()
            self.middle = QVBoxLayout()
            self.middlegrid = QGridLayout()
    
            self.topbarmid1 = QVBoxLayout()
            self.topbarmid2 = QHBoxLayout()
    
        
            self.topbarmid1.addWidget(self.searchbar)
            self.topbarmid1.addLayout(self.topbarmid2)
            self.topbarmid1.setContentsMargins(300,0,350,0)
    
            self.topbarmid2.addStretch()
            self.topbarmid2.addWidget(self.confirmbutton)
    
            self.topbar.addWidget(self.logoutbutton)
            self.topbar.addLayout(self.topbarmid1)
    
            self.middle.addLayout(self.middlegrid,95)
    
            self.rightlayout.addLayout(self.topbar,10)
            self.rightlayout.addLayout(self.middle,90)
    
            self.mainlayout.addLayout(self.sidebar,17)
            self.mainlayout.addLayout(self.rightlayout,83)
    
            self.setLayout(self.mainlayout)
    

    You can see that I am only giving the topbar 10, and the middle 90. However, this is not holding.
    Layout.PNG

    Issue.PNG


Log in to reply