Skip to content Skip to sidebar Skip to footer

Mainwindow Widget Resize (pyside)

I have a problem with the resize of the MainWindow of a GUI Application. This is what i see when i try to run the Application: Link Image 1 and what happen when i try to resize it

Solution 1:

If you want a resize to not modify the center of the QGridLayout, you need to put a different stretch on some surrounding rows.

I added a row above and below your content, and a column to the left and right of your content and added a stretch.

http://doc.qt.io/qt-4.8/qgridlayout.html#setRowStretch

http://doc.qt.io/qt-4.8/qgridlayout.html#setColumnStretch

enter image description here

def setupGridUI(self):
    widget = QWidget()
    layout = QGridLayout()
    width, height = 10, 10

    root_x, root_y = random.randrange(width), random.randrange(height)

    for x in range(width):
        for y in range(height):
            random_wall = random.randrange(3)
            if x == root_x and y == root_y:
                label = ClickableLabel(x, y, False, True)
            else:
                if random_wall == 0:
                    label = ClickableLabel(x, y, True)
                else:
                    label = ClickableLabel(x, y)

            layout.addWidget(label, x+1, y+1) # modified

    # added the following 4 lines
    layout.setRowStretch(0, 1);
    layout.setRowStretch(height+2, 1);
    layout.setColumnStretch(0, 1);
    layout.setColumnStretch(width+2, 1);

    widget.setLayout(layout)
    self.setCentralWidget(widget)

    self.setStyleSheet("QMainWindow {background: 'purple'}")

Hope that helps.

Post a Comment for "Mainwindow Widget Resize (pyside)"