Bringing QGridLayout to the same column width

16 Views Asked by At

I've got a window with a QGridLayout, and because of the QLineEdit in the first column, it's getting wider than the other one. How do I fix that?

Current behavior:

Window screeenshot

Window class:

class MainWindow(QMainWindow):

    def __init__(self):

        super().__init__()

        layout = QGridLayout()

        self.pid_input = QLineEdit()
        layout.addWidget(self.pid_input, 0, 0)
        self.pid_input.setPlaceholderText('Executable or PID to hook to')
        layout.addWidget(hook_btn := QPushButton('Hook'), 0, 1)
        hook_btn.clicked.connect(self.hook)

        layout.addWidget(terminate_btn := QPushButton('Terminate'), 1, 0)
        layout.addWidget(kill_btn := QPushButton('Kill'), 1, 1)

        layout.addWidget(suspend_btn := QPushButton('Suspend'), 2, 0)
        layout.addWidget(resume_btn := QPushButton('Resume'), 2, 1)
                         
        layout.addWidget(niceness_label := QLabel('Niceness: N/A'), 3, 0, 1, 2)
        niceness_label.setAlignment(Qt.AlignmentFlag.AlignHCenter)

        layout.addWidget(nastier := QPushButton('Nastier'), 4, 0)
        layout.addWidget(nicer := QPushButton('Nicer'), 4, 1)

        wrapper = QWidget()
        wrapper.setLayout(layout)
        self.setCentralWidget(wrapper)

        self.show()
0

There are 0 best solutions below