Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Unable to set "QMainWindow" shadow with "FramelessWindowHint" window type
Forum Update on Monday, May 27th 2025

Unable to set "QMainWindow" shadow with "FramelessWindowHint" window type

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 2 Posters 673 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • bashtianB Offline
    bashtianB Offline
    bashtian
    wrote on last edited by
    #1

    Hello,
    I am unable to apply a shadow effect to my custom QMainWindow which has FramelessWindowHint flag, what ever I do, its never there.
    Does anyone know how to bring back the window shadow effect in windows?

    I am using:
    Windows 11
    Python 3.11.3
    PyQt6==6.5.1

    Here is a reproduceable snippet:

    import sys
    from PyQt6.QtWidgets import (
        QGraphicsDropShadowEffect,
        QApplication,
        QMainWindow,
        QPushButton,
        QWidget,
        QVBoxLayout,
    )
    from PyQt6.QtGui import QColor
    from PyQt6.QtCore import Qt, QCoreApplication
    
    
    class MainWindow(QMainWindow):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            self.setWindowTitle('Test')
            self.setWindowFlag(Qt.WindowType.FramelessWindowHint)
            self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
    
            # Shadow?
            shadow = QGraphicsDropShadowEffect(self)
            shadow.setBlurRadius(20)
            shadow.setColor(QColor("red"))
            self.setGraphicsEffect(shadow)
    
            # Central Widget
            central_widget = QWidget(self)
            central_widget.setFixedSize(300, 300)
            central_widget.setObjectName('central_widget')
            central_widget.setStyleSheet("""
                QWidget#central_widget{
                    background-color: lightblue;
                }
            """)
            central_widget.setLayout(QVBoxLayout())
            central_widget.layout().setAlignment(Qt.AlignmentFlag.AlignHCenter)
    
            # Just for convenience
            button = QPushButton("Close", central_widget)
            button.setFixedSize(100, 20)
            button.clicked.connect(QCoreApplication.instance().quit)
            central_widget.layout().addWidget(button)
    
            self.setCentralWidget(central_widget)
            self.show()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        window = MainWindow()
        sys.exit(app.exec())
    
    M 1 Reply Last reply
    0
    • bashtianB bashtian

      Hello,
      I am unable to apply a shadow effect to my custom QMainWindow which has FramelessWindowHint flag, what ever I do, its never there.
      Does anyone know how to bring back the window shadow effect in windows?

      I am using:
      Windows 11
      Python 3.11.3
      PyQt6==6.5.1

      Here is a reproduceable snippet:

      import sys
      from PyQt6.QtWidgets import (
          QGraphicsDropShadowEffect,
          QApplication,
          QMainWindow,
          QPushButton,
          QWidget,
          QVBoxLayout,
      )
      from PyQt6.QtGui import QColor
      from PyQt6.QtCore import Qt, QCoreApplication
      
      
      class MainWindow(QMainWindow):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
      
              self.setWindowTitle('Test')
              self.setWindowFlag(Qt.WindowType.FramelessWindowHint)
              self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
      
              # Shadow?
              shadow = QGraphicsDropShadowEffect(self)
              shadow.setBlurRadius(20)
              shadow.setColor(QColor("red"))
              self.setGraphicsEffect(shadow)
      
              # Central Widget
              central_widget = QWidget(self)
              central_widget.setFixedSize(300, 300)
              central_widget.setObjectName('central_widget')
              central_widget.setStyleSheet("""
                  QWidget#central_widget{
                      background-color: lightblue;
                  }
              """)
              central_widget.setLayout(QVBoxLayout())
              central_widget.layout().setAlignment(Qt.AlignmentFlag.AlignHCenter)
      
              # Just for convenience
              button = QPushButton("Close", central_widget)
              button.setFixedSize(100, 20)
              button.clicked.connect(QCoreApplication.instance().quit)
              central_widget.layout().addWidget(button)
      
              self.setCentralWidget(central_widget)
              self.show()
      
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
          window = MainWindow()
          sys.exit(app.exec())
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @bashtian
      Hi,
      Drop Shadow cannot be drawn outside your window.
      See here

      bashtianB 1 Reply Last reply
      0
      • M mpergand

        @bashtian
        Hi,
        Drop Shadow cannot be drawn outside your window.
        See here

        bashtianB Offline
        bashtianB Offline
        bashtian
        wrote on last edited by
        #3

        @mpergand
        thanks for the reply, so if I understand correctly I should make the window a bit bigger thant the central_widget and then the shadow should affect the central_widget ?

        bashtianB 1 Reply Last reply
        0
        • bashtianB bashtian

          @mpergand
          thanks for the reply, so if I understand correctly I should make the window a bit bigger thant the central_widget and then the shadow should affect the central_widget ?

          bashtianB Offline
          bashtianB Offline
          bashtian
          wrote on last edited by bashtian
          #4

          that seems to do the trick, adding a self.setContentsMargins(20, 20, 20, 20) on the QMainWindow, adds margin inside making it bigger, and then the shadow appear on the central widget, altho need to check if it doesnt break anything else :D

          edit1: it offset all the geometry by the margin number - a bit messy but need to take it into consideration for the moving part

          bashtianB 1 Reply Last reply
          0
          • bashtianB bashtian

            that seems to do the trick, adding a self.setContentsMargins(20, 20, 20, 20) on the QMainWindow, adds margin inside making it bigger, and then the shadow appear on the central widget, altho need to check if it doesnt break anything else :D

            edit1: it offset all the geometry by the margin number - a bit messy but need to take it into consideration for the moving part

            bashtianB Offline
            bashtianB Offline
            bashtian
            wrote on last edited by
            #5

            Too many undesirable effects, for example, the border are not click throu so its not convenient, I guess I ll have to live without a border, too bad its not possible.

            M 1 Reply Last reply
            0
            • bashtianB bashtian

              Too many undesirable effects, for example, the border are not click throu so its not convenient, I guess I ll have to live without a border, too bad its not possible.

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              @bashtian
              Have a try with:

              Qt::WA_TransparentForMouseEvents
              When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

              bashtianB 1 Reply Last reply
              0
              • M mpergand

                @bashtian
                Have a try with:

                Qt::WA_TransparentForMouseEvents
                When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

                bashtianB Offline
                bashtianB Offline
                bashtian
                wrote on last edited by
                #7

                @mpergand I did try it but it has no effect on the shadow, when added to the QMainWindow flags

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved