Qt QGraphicsDropShadowEffect is not showing

后端 未结 3 1376
我寻月下人不归
我寻月下人不归 2021-01-14 22:04

I am creating a custom widget my_widget inheriting from QWidget.

Here, I have a label to which I would like to apply QGraphicsDropSha

3条回答
  •  半阙折子戏
    2021-01-14 22:57

    See if this works for you:

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    import sip
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)
    
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    
    class testShadow(QWidget):
        def __init__(self, parent=None):
            super(testShadow, self).__init__(parent)
    
            self.resize(94, 35)
            self.verticalLayout = QVBoxLayout(self)
            self.verticalLayout.setObjectName("verticalLayout")
            self.label = QLabel(self)
            self.label.setText("Text Label")
    
            self.shadow = QGraphicsDropShadowEffect(self)
            self.shadow.setBlurRadius(5)
            self.label.setGraphicsEffect(self.shadow)
    
            self.verticalLayout.addWidget(self.label)
    
    if __name__ == "__main__":
        import  sys
    
        app = QApplication(sys.argv)
        main = testShadow()
        main.show()
        sys.exit(app.exec_())
    

    image

提交回复
热议问题