import sys

from PySide6 import QtWidgets, QtCore
from PySide6.QtWidgets import QApplication, QPushButton, QGridLayout, QDialog

qss = f"""
    QPushButton {{
        border: 1px solid green;
    }}
    """


class ButtonGrid(QDialog):
    def __init__(self,  title, parent=None, dialogStyleSheet=None, buttonStyleSheet=None):
        super().__init__(parent)
        self.setWindowTitle(title)
        if dialogStyleSheet:
            self.setStyleSheet(dialogStyleSheet)
        layout = QGridLayout()
        #
        layout.setSpacing(7)

        rows, cols = 2, 2
        for r in range(rows):
            for c in range(cols):
                btn = self.make_button(self, f"Btn {r, c}", styleSheet=buttonStyleSheet)
                layout.addWidget(btn, r, c)

        self.setLayout(layout)

    def make_button(self, parent, text: str, styleSheet=None) -> QPushButton:
        btn = QPushButton(text, parent=parent)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred
        )
        btn.setSizePolicy(sizePolicy)
        btn.setMinimumSize(QtCore.QSize(105, 93))
        if styleSheet:
            btn.setStyleSheet(styleSheet)
        return btn


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win1 = ButtonGrid("With vertical spacing defect", dialogStyleSheet=qss)
    win2 = ButtonGrid("Without defect", buttonStyleSheet=qss)
    win1.show()
    win2.show()
    sys.exit(app.exec())
