I’m tring to create a rounded windows without title bar. but the windows corners are always sharp

I’m currently working on a PyQt5 application where I have a translucent widget with rounded corners inside a translucent window. However, despite setting the border-radius property for the widget, the corners are not appearing rounded as expected.

I expect the translucent widget to have rounded corner but for whatever reson it won’t work.

I’m using pyqt 5.15.10 and python 3.11

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtGui import QFont
class TranslucentWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setGeometry(0, 0, 500, 600)
self.setStyleSheet(
"background-color: rgba(255, 255, 255, 150);"
"border-radius: 20px;"
)
class TranslucentWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.oldPos = self.pos()
def initUI(self):
self.setFixedSize(500, 600) # Set fixed width and height
self.setWindowTitle('Translucent Window')
self.setStyleSheet(
"background: transparent;"
"border-radius: 20px;" # Set border radius for the window
)
self.setWindowOpacity(0.9) # Set window opacity to 0.9 to make it transparent
# Remove the title bar
self.setWindowFlags(Qt.FramelessWindowHint)
# Load Roboto font
font = QFont()
font.setFamily("Roboto")
# Create translucent widget
self.translucentWidget = TranslucentWidget(self)
# Create minimize button
self.minimizeButton = QPushButton('_', self.translucentWidget)
self.minimizeButton.setGeometry(430, 10, 30, 30)
self.minimizeButton.setFont(font) # Set font to Roboto
self.minimizeButton.setStyleSheet(
"background-color: white;" # Set background color to opaque white
"border-radius: 15px;"
)
self.minimizeButton.clicked.connect(self.showMinimized)
# Create close button
self.closeButton = QPushButton('X', self.translucentWidget)
self.closeButton.setGeometry(465, 10, 30, 30)
self.closeButton.setFont(font) # Set font to Roboto
self.closeButton.setStyleSheet(
"background-color: white;" # Set background color to opaque white
"border-radius: 15px;"
)
self.closeButton.clicked.connect(self.close)
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint (event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = TranslucentWindow()
window.show()
sys.exit(app.exec_())
</code>
<code>import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtCore import Qt, QPoint from PyQt5.QtGui import QFont class TranslucentWidget(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setGeometry(0, 0, 500, 600) self.setStyleSheet( "background-color: rgba(255, 255, 255, 150);" "border-radius: 20px;" ) class TranslucentWindow(QWidget): def __init__(self): super().__init__() self.initUI() self.oldPos = self.pos() def initUI(self): self.setFixedSize(500, 600) # Set fixed width and height self.setWindowTitle('Translucent Window') self.setStyleSheet( "background: transparent;" "border-radius: 20px;" # Set border radius for the window ) self.setWindowOpacity(0.9) # Set window opacity to 0.9 to make it transparent # Remove the title bar self.setWindowFlags(Qt.FramelessWindowHint) # Load Roboto font font = QFont() font.setFamily("Roboto") # Create translucent widget self.translucentWidget = TranslucentWidget(self) # Create minimize button self.minimizeButton = QPushButton('_', self.translucentWidget) self.minimizeButton.setGeometry(430, 10, 30, 30) self.minimizeButton.setFont(font) # Set font to Roboto self.minimizeButton.setStyleSheet( "background-color: white;" # Set background color to opaque white "border-radius: 15px;" ) self.minimizeButton.clicked.connect(self.showMinimized) # Create close button self.closeButton = QPushButton('X', self.translucentWidget) self.closeButton.setGeometry(465, 10, 30, 30) self.closeButton.setFont(font) # Set font to Roboto self.closeButton.setStyleSheet( "background-color: white;" # Set background color to opaque white "border-radius: 15px;" ) self.closeButton.clicked.connect(self.close) def mousePressEvent(self, event): self.oldPos = event.globalPos() def mouseMoveEvent(self, event): delta = QPoint (event.globalPos() - self.oldPos) self.move(self.x() + delta.x(), self.y() + delta.y()) self.oldPos = event.globalPos() if __name__ == '__main__': app = QApplication(sys.argv) window = TranslucentWindow() window.show() sys.exit(app.exec_()) </code>
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtGui import QFont

class TranslucentWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setGeometry(0, 0, 500, 600)
        self.setStyleSheet(
            "background-color: rgba(255, 255, 255, 150);"
            "border-radius: 20px;"
        )

class TranslucentWindow(QWidget):
    def __init__(self):
        super().__init__()
        
        self.initUI()
        self.oldPos = self.pos()
        
    def initUI(self):
        self.setFixedSize(500, 600)  # Set fixed width and height
        self.setWindowTitle('Translucent Window')
        self.setStyleSheet(
            "background: transparent;"
            "border-radius: 20px;"  # Set border radius for the window
        )
        self.setWindowOpacity(0.9)  # Set window opacity to 0.9 to make it transparent
        
        # Remove the title bar
        self.setWindowFlags(Qt.FramelessWindowHint)
        
        # Load Roboto font
        font = QFont()
        font.setFamily("Roboto")
        
        # Create translucent widget
        self.translucentWidget = TranslucentWidget(self)
        
        # Create minimize button
        self.minimizeButton = QPushButton('_', self.translucentWidget)
        self.minimizeButton.setGeometry(430, 10, 30, 30)
        self.minimizeButton.setFont(font)  # Set font to Roboto
        self.minimizeButton.setStyleSheet(
            "background-color: white;"  # Set background color to opaque white
            "border-radius: 15px;"
        )
        self.minimizeButton.clicked.connect(self.showMinimized)
        
        # Create close button
        self.closeButton = QPushButton('X', self.translucentWidget)
        self.closeButton.setGeometry(465, 10, 30, 30)
        self.closeButton.setFont(font)  # Set font to Roboto
        self.closeButton.setStyleSheet(
            "background-color: white;"  # Set background color to opaque white
            "border-radius: 15px;"
        )
        self.closeButton.clicked.connect(self.close)
        
    def mousePressEvent(self, event):
        self.oldPos = event.globalPos()
        
    def mouseMoveEvent(self, event):
        delta = QPoint (event.globalPos() - self.oldPos)
        self.move(self.x() + delta.x(), self.y() + delta.y())
        self.oldPos = event.globalPos()
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = TranslucentWindow()
    window.show()
    sys.exit(app.exec_())

Setting the border-radius property in the stylesheet of the TranslucentWidget class.
Setting the border-radius property for both the window and the widget

New contributor

Sudharsan R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật