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. How to set the QGraphicsDropShadowEffect on the drop down menu of a QComboBox?
Forum Update on Monday, May 27th 2025

How to set the QGraphicsDropShadowEffect on the drop down menu of a QComboBox?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 261 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.
  • M Offline
    M Offline
    Mizmas
    wrote on 13 Mar 2025, 12:23 last edited by
    #1

    I tried it like this self.combobox.view().setGraphicsEffect(self.shadow_effect) but it doesn't work.

    1 Reply Last reply
    0
    • S SGaist moved this topic from General and Desktop on 13 Mar 2025, 20:43
    • S Offline
      S Offline
      Shankarlinga M
      wrote on 14 Mar 2025, 13:00 last edited by Shankarlinga M
      #2

      Instead of applying the shadow to the view, try setting it on the entire ComboBox or its delegate items.

      Apply Shadow to the Entire ComboBox:
      from PyQt5.QtWidgets import QApplication, QComboBox, QGraphicsDropShadowEffect
      from PyQt5.QtGui import QColor
      from PyQt5.QtCore import Qt

      app = QApplication([])

      combobox = QComboBox()
      combobox.addItems(["Option 1", "Option 2", "Option 3"])

      Create shadow effect
      shadow_effect = QGraphicsDropShadowEffect()
      shadow_effect.setBlurRadius(10)
      shadow_effect.setOffset(3, 3)
      shadow_effect.setColor(QColor(0, 0, 0, 100))

      Apply to ComboBox
      combobox.setGraphicsEffect(shadow_effect)

      combobox.show()
      app.exec_()
      If you only want the shadow effect on the dropdown list items, you must customize the item delegate.
      from PyQt5.QtWidgets import QApplication, QComboBox, QStyledItemDelegate, QGraphicsDropShadowEffect
      from PyQt5.QtGui import QColor
      from PyQt5.QtCore import Qt

      class ShadowDelegate(QStyledItemDelegate):
      def paint(self, painter, option, index):
      shadow = QGraphicsDropShadowEffect()
      shadow.setBlurRadius(10)
      shadow.setOffset(3, 3)
      shadow.setColor(QColor(0, 0, 0, 100))

          painter.setPen(Qt.NoPen)
          shadow.drawSource(painter)
          super().paint(painter, option, index)
      

      app = QApplication([])

      combobox = QComboBox()
      combobox.addItems(["Option 1", "Option 2", "Option 3"])
      combobox.setItemDelegate(ShadowDelegate())

      combobox.show()
      app.exec_()

      M 1 Reply Last reply 17 Mar 2025, 12:54
      0
      • S Shankarlinga M
        14 Mar 2025, 13:00

        Instead of applying the shadow to the view, try setting it on the entire ComboBox or its delegate items.

        Apply Shadow to the Entire ComboBox:
        from PyQt5.QtWidgets import QApplication, QComboBox, QGraphicsDropShadowEffect
        from PyQt5.QtGui import QColor
        from PyQt5.QtCore import Qt

        app = QApplication([])

        combobox = QComboBox()
        combobox.addItems(["Option 1", "Option 2", "Option 3"])

        Create shadow effect
        shadow_effect = QGraphicsDropShadowEffect()
        shadow_effect.setBlurRadius(10)
        shadow_effect.setOffset(3, 3)
        shadow_effect.setColor(QColor(0, 0, 0, 100))

        Apply to ComboBox
        combobox.setGraphicsEffect(shadow_effect)

        combobox.show()
        app.exec_()
        If you only want the shadow effect on the dropdown list items, you must customize the item delegate.
        from PyQt5.QtWidgets import QApplication, QComboBox, QStyledItemDelegate, QGraphicsDropShadowEffect
        from PyQt5.QtGui import QColor
        from PyQt5.QtCore import Qt

        class ShadowDelegate(QStyledItemDelegate):
        def paint(self, painter, option, index):
        shadow = QGraphicsDropShadowEffect()
        shadow.setBlurRadius(10)
        shadow.setOffset(3, 3)
        shadow.setColor(QColor(0, 0, 0, 100))

            painter.setPen(Qt.NoPen)
            shadow.drawSource(painter)
            super().paint(painter, option, index)
        

        app = QApplication([])

        combobox = QComboBox()
        combobox.addItems(["Option 1", "Option 2", "Option 3"])
        combobox.setItemDelegate(ShadowDelegate())

        combobox.show()
        app.exec_()

        M Offline
        M Offline
        Mizmas
        wrote on 17 Mar 2025, 12:54 last edited by
        #3

        @Shankarlinga-M IDK about PyQt5, but in PyQt6, setting the shadow effect on the combobox itself will only apply the shadow on the combobox, but not the dropdown
        Screenshot_1.png
        Screenshot_3.png

                self.combobox = QComboBox(self)
                self.apply_static_shadow(self.combobox)
        
            def apply_static_shadow(self, widget):
                shadow = QGraphicsDropShadowEffect()
                shadow.setOffset(5, 5)
                shadow.setColor(QColor("blue"))
                widget.setGraphicsEffect(shadow)
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Shankarlinga M
          wrote on 19 Mar 2025, 04:30 last edited by Shankarlinga M
          #4

          In PyQt6, setting a QGraphicsDropShadowEffect on the QComboBox itself only applies the effect to the main widget, not the dropdown menu. To apply the shadow effect to the dropdown, you need to set the effect on the QComboBox's view().

          Here's how you can apply a drop shadow effect to the dropdown menu in PyQt6:

          from PyQt6.QtWidgets import QApplication, QComboBox, QGraphicsDropShadowEffect
          from PyQt6.QtGui import QColor
          from PyQt6.QtCore import Qt

          app = QApplication([])

          Create ComboBox
          combobox = QComboBox()
          combobox.addItems(["Option 1", "Option 2", "Option 3"])

          Create shadow effect
          shadow_effect = QGraphicsDropShadowEffect()
          shadow_effect.setBlurRadius(10)
          shadow_effect.setOffset(5, 5)
          shadow_effect.setColor(QColor(0, 0, 255, 100)) # Blue shadow with transparency

          Apply shadow effect to dropdown menu (view)
          combobox.view().setGraphicsEffect(shadow_effect)

          combobox.show()
          app.exec()

          M 2 Replies Last reply 20 Mar 2025, 23:44
          0
          • S Shankarlinga M
            19 Mar 2025, 04:30

            In PyQt6, setting a QGraphicsDropShadowEffect on the QComboBox itself only applies the effect to the main widget, not the dropdown menu. To apply the shadow effect to the dropdown, you need to set the effect on the QComboBox's view().

            Here's how you can apply a drop shadow effect to the dropdown menu in PyQt6:

            from PyQt6.QtWidgets import QApplication, QComboBox, QGraphicsDropShadowEffect
            from PyQt6.QtGui import QColor
            from PyQt6.QtCore import Qt

            app = QApplication([])

            Create ComboBox
            combobox = QComboBox()
            combobox.addItems(["Option 1", "Option 2", "Option 3"])

            Create shadow effect
            shadow_effect = QGraphicsDropShadowEffect()
            shadow_effect.setBlurRadius(10)
            shadow_effect.setOffset(5, 5)
            shadow_effect.setColor(QColor(0, 0, 255, 100)) # Blue shadow with transparency

            Apply shadow effect to dropdown menu (view)
            combobox.view().setGraphicsEffect(shadow_effect)

            combobox.show()
            app.exec()

            M Offline
            M Offline
            Mizmas
            wrote on 20 Mar 2025, 23:44 last edited by
            #5

            @Shankarlinga-M Look at my original post, that's what I tried and it doesn't seem to work, have you tested this? I'm on PyQt6 Qt version 6.8.2

            1 Reply Last reply
            0
            • S Shankarlinga M
              19 Mar 2025, 04:30

              In PyQt6, setting a QGraphicsDropShadowEffect on the QComboBox itself only applies the effect to the main widget, not the dropdown menu. To apply the shadow effect to the dropdown, you need to set the effect on the QComboBox's view().

              Here's how you can apply a drop shadow effect to the dropdown menu in PyQt6:

              from PyQt6.QtWidgets import QApplication, QComboBox, QGraphicsDropShadowEffect
              from PyQt6.QtGui import QColor
              from PyQt6.QtCore import Qt

              app = QApplication([])

              Create ComboBox
              combobox = QComboBox()
              combobox.addItems(["Option 1", "Option 2", "Option 3"])

              Create shadow effect
              shadow_effect = QGraphicsDropShadowEffect()
              shadow_effect.setBlurRadius(10)
              shadow_effect.setOffset(5, 5)
              shadow_effect.setColor(QColor(0, 0, 255, 100)) # Blue shadow with transparency

              Apply shadow effect to dropdown menu (view)
              combobox.view().setGraphicsEffect(shadow_effect)

              combobox.show()
              app.exec()

              M Offline
              M Offline
              Mizmas
              wrote on 21 Mar 2025, 17:35 last edited by
              #6

              @Shankarlinga-M I did some testing and it seems that the style from QStyleFactory can override the behavior of effects in the combobox's view() and view().viewport()

              You can try printing the available styles and changing them like this:

              print(QStyleFactory.keys())
              
              app = QApplication(sys.argv)
              app.setStyle(QStyleFactory.create('Windows'))
              

              It also seems that the QGraphicsDropShadowEffect() expands the bounding box of the widget you apply it to, but doesn't expand the bounding box of the combobox.view()

              1 Reply Last reply
              0

              2/6

              14 Mar 2025, 13:00

              topic:navigator.unread, 4
              • Login

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