PySide6 Rounded Border Window

769 views Asked by At

I am trying to create a frameless round-corner window using QWidget. I have tried using border-radius in Stylesheet but it's not working.

Here is the code:

from PySide6.QtCore import Qt, QSize
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton


class MainWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.setFixedSize(QSize(400, 400))

        self.setStyleSheet("""
                           MainWidget {
                               border-radius: 25px;
                               background: red;
                           }
                           """)
        self.vertical_layout = QVBoxLayout()

        self.button = QPushButton('Exit')
        self.button.clicked.connect(lambda: self.close())

        self.vertical_layout.addWidget(self.button, alignment=Qt.AlignCenter)
        self.setLayout(self.vertical_layout)


app = QApplication([])
widget = MainWidget()
widget.show()
app.exec()

This gives the following result:

QWidget_Window

If I use the Masking technique then it is not Anti-Aliased and produces blurred corners.

Any help will be appreciated!

0

There are 0 answers