Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't use "setGraphicsEffect"?

Can't use "setGraphicsEffect"?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 689 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.
  • R Offline
    R Offline
    Rangerguy128
    wrote on last edited by Rangerguy128
    #1

    I've been trying to implement methods to add some shadow effects to some parts of the UI (i.e. the header) and was told to import/install PySide, PyQt and QT-PyQt-PySide-Custom-Widgets (note I'm using PyQt5 and PySide6) However, setGraphicsEffects doesn't seem to work. In other words, it acts like there is no said function available. Here's what the code looks like:

    shadow_elements = { "left_menu","frame_3", "frame_5", "header", "frame_8"}
    
    class MainWindow(QMainWindow):
            def __init__(self,parent=None):
                QMainWindow.__init__(self)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                
                self.setMinimumSize(850,600)
                
                for x in shadow_elements:
                    
                    effect = QtWidgets.QGraphicsDropShadowEffect(self)
                    effect.setBlurRadius(18)
                    effect.setXOffset(0)
                    effect.setYOffset(0)
                    effect.setColor(QColor(0,0,0,255))
                    getattr(self.ui,x).setGraphicsEffect(effect) #isn't highlighted like the rest of teh functions here
                            
                self.show()
    

    Am I missing something?

    M 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please provide a complete minimal script that shows the issue.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • R Rangerguy128

        I've been trying to implement methods to add some shadow effects to some parts of the UI (i.e. the header) and was told to import/install PySide, PyQt and QT-PyQt-PySide-Custom-Widgets (note I'm using PyQt5 and PySide6) However, setGraphicsEffects doesn't seem to work. In other words, it acts like there is no said function available. Here's what the code looks like:

        shadow_elements = { "left_menu","frame_3", "frame_5", "header", "frame_8"}
        
        class MainWindow(QMainWindow):
                def __init__(self,parent=None):
                    QMainWindow.__init__(self)
                    self.ui = Ui_MainWindow()
                    self.ui.setupUi(self)
                    
                    self.setMinimumSize(850,600)
                    
                    for x in shadow_elements:
                        
                        effect = QtWidgets.QGraphicsDropShadowEffect(self)
                        effect.setBlurRadius(18)
                        effect.setXOffset(0)
                        effect.setYOffset(0)
                        effect.setColor(QColor(0,0,0,255))
                        getattr(self.ui,x).setGraphicsEffect(effect) #isn't highlighted like the rest of teh functions here
                                
                    self.show()
        

        Am I missing something?

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

        @Rangerguy128

        Shadows can't be drawn outside of the parent widget, only inside.
        See https://forum.qt.io/post/740663

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Please provide a complete minimal script that shows the issue.

          R Offline
          R Offline
          Rangerguy128
          wrote on last edited by
          #4

          @SGaist Here's the error it gives me when I run the file:

          Traceback (most recent call last):
            File "C:\Users\UserPC\OneDrive\Documentos\ProjectSICI\propiedadesmain.py", line 12, in <module>
              from Custom_Widgets.Widgets import *
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\__init__.py", line 12, in <module>
              from Custom_Widgets.Qss.SvgToPngIcons import NewIconsGenerator
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\Qss\SvgToPngIcons.py", line 22, in <module>
              import cairosvg
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\__init__.py", line 26, in <module>
              from . import surface  # noqa isort:skip
              ^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\surface.py", line 9, in <module>
              import cairocffi as cairo
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\__init__.py", line 47, in <module>
              cairo = dlopen(
                      ^^^^^^^
            File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\__init__.py", line 44, in dlopen
              raise OSError(error_message)  # pragma: no cover
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          OSError: no library called "cairo-2" was found
          no library called "cairo" was found
          no library called "libcairo-2" was found
          cannot load library 'libcairo.so.2': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
          cannot load library 'libcairo.2.dylib': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'    
          cannot load library 'libcairo-2.dll': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'        
          
          

          As for the full script of the file, here's what I wrote with the imports:

          import os
          import sys
          
          import csv
          from propiedades import *
          
          
          from PyQt5 import QtCore, QtGui, QtWidgets
          from PyQt5.QtWidgets import QApplication, QMainWindow
          from PyQt5.QtGui import *
          from PyQt5.QtCore import *
          from Custom_Widgets.Widgets import *
          # from PySide6.QtGui import *
          # from PySide6.QtCore import *
          # from PySide6.QtWidgets import *
          
          shadow_elements = { "left_menu","frame_3", "frame_5", "header", "frame_8"}
          from functools import partial
          
          class MainWindow(QMainWindow):
                  def __init__(self,parent=None):
                      QMainWindow.__init__(self)
                      self.ui = Ui_MainWindow()
                      self.ui.setupUi(self)
                      
                      self.setMinimumSize(850,600)
                      
                      loadJsonStyle(self, self.ui)
                      for x in shadow_elements:
                          
                          effect = QtWidgets.QGraphicsDropShadowEffect(self)
                          effect.setBlurRadius(18)
                          effect.setXOffset(0)
                          effect.setYOffset(0)
                          effect.setColor(QColor(0,0,0,255))
                          getattr(self.ui,x).setGraphicsEffect(effect)
                      
                      
                      self.show()
                      
          if __name__ == "__main__":
              import sys
              app = QApplication(sys.argv)
              window = QMainWindow()
              window.show()
              sys.exit(app.exec_())
          
          
          JonBJ 1 Reply Last reply
          0
          • R Rangerguy128

            @SGaist Here's the error it gives me when I run the file:

            Traceback (most recent call last):
              File "C:\Users\UserPC\OneDrive\Documentos\ProjectSICI\propiedadesmain.py", line 12, in <module>
                from Custom_Widgets.Widgets import *
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\__init__.py", line 12, in <module>
                from Custom_Widgets.Qss.SvgToPngIcons import NewIconsGenerator
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\Qss\SvgToPngIcons.py", line 22, in <module>
                import cairosvg
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\__init__.py", line 26, in <module>
                from . import surface  # noqa isort:skip
                ^^^^^^^^^^^^^^^^^^^^^
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\surface.py", line 9, in <module>
                import cairocffi as cairo
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\__init__.py", line 47, in <module>
                cairo = dlopen(
                        ^^^^^^^
              File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\__init__.py", line 44, in dlopen
                raise OSError(error_message)  # pragma: no cover
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            OSError: no library called "cairo-2" was found
            no library called "cairo" was found
            no library called "libcairo-2" was found
            cannot load library 'libcairo.so.2': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
            cannot load library 'libcairo.2.dylib': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'    
            cannot load library 'libcairo-2.dll': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'        
            
            

            As for the full script of the file, here's what I wrote with the imports:

            import os
            import sys
            
            import csv
            from propiedades import *
            
            
            from PyQt5 import QtCore, QtGui, QtWidgets
            from PyQt5.QtWidgets import QApplication, QMainWindow
            from PyQt5.QtGui import *
            from PyQt5.QtCore import *
            from Custom_Widgets.Widgets import *
            # from PySide6.QtGui import *
            # from PySide6.QtCore import *
            # from PySide6.QtWidgets import *
            
            shadow_elements = { "left_menu","frame_3", "frame_5", "header", "frame_8"}
            from functools import partial
            
            class MainWindow(QMainWindow):
                    def __init__(self,parent=None):
                        QMainWindow.__init__(self)
                        self.ui = Ui_MainWindow()
                        self.ui.setupUi(self)
                        
                        self.setMinimumSize(850,600)
                        
                        loadJsonStyle(self, self.ui)
                        for x in shadow_elements:
                            
                            effect = QtWidgets.QGraphicsDropShadowEffect(self)
                            effect.setBlurRadius(18)
                            effect.setXOffset(0)
                            effect.setYOffset(0)
                            effect.setColor(QColor(0,0,0,255))
                            getattr(self.ui,x).setGraphicsEffect(effect)
                        
                        
                        self.show()
                        
            if __name__ == "__main__":
                import sys
                app = QApplication(sys.argv)
                window = QMainWindow()
                window.show()
                sys.exit(app.exec_())
            
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Rangerguy128
            In your original post you just said "setGraphicsEffects doesn't seem to work", you did not mention anything about the error you show now? The Custom_Widgets module seems to need this cairo stuff. You seem to be using Windows: do you have a libcairo-2.dll file anywhere at all? Googling libcairo-2.dll shows plenty of results about it being "missing", e.g. maybe Python: OSError: cannot load library libcairo.so.2.

            R 1 Reply Last reply
            0
            • JonBJ JonB

              @Rangerguy128
              In your original post you just said "setGraphicsEffects doesn't seem to work", you did not mention anything about the error you show now? The Custom_Widgets module seems to need this cairo stuff. You seem to be using Windows: do you have a libcairo-2.dll file anywhere at all? Googling libcairo-2.dll shows plenty of results about it being "missing", e.g. maybe Python: OSError: cannot load library libcairo.so.2.

              R Offline
              R Offline
              Rangerguy128
              wrote on last edited by
              #6

              @JonB I see, maybe that's also why setGraphicsEffect isn't highlighted like the rest? Is there anyway to import the cairo library? I'm using Python 3.11.9 and I'm not sure if it's because of the version or not (cant use 3.12 as that one doesn't support PyQt6-tools yet)

              JonBJ 1 Reply Last reply
              0
              • R Rangerguy128

                @JonB I see, maybe that's also why setGraphicsEffect isn't highlighted like the rest? Is there anyway to import the cairo library? I'm using Python 3.11.9 and I'm not sure if it's because of the version or not (cant use 3.12 as that one doesn't support PyQt6-tools yet)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Rangerguy128
                This is not my area. I suggested you discover whether libcairo-2.dll exists anywhere for you. Searching for e.g. python cairo indicates to me you have to install it, perhaps via pip or pyPI? You may have done that, but I suspect that is only the bindings for Python? Do you have to install cairo itself as a (binary) package, which includes e.g. libcairo-2.dll, so that the Python bindings can use it?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  The first thing you should do is avoid star imports. You don't know what you are pulling there and it makes your code less readable and understandable.

                  Next, remove everything that is not related to your current Qt issue. Deal with each problem one after the other.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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