Qt QGraphicsDropShadowEffect is not showing

后端 未结 3 1350
我寻月下人不归
我寻月下人不归 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:40

    I have only every tried to use this (and used it successfully) in QGraphicsScene situations. This works for me, while trying to set it on a normal QWidget actually crashes the entire application:

    from PyQt4 import QtGui
    
    class Graphics(QtGui.QWidget):
        def __init__(self):
            super(Graphics, self).__init__()
    
            layout = QtGui.QVBoxLayout(self)
            layout.setMargin(0)
    
            shad = QtGui.QGraphicsDropShadowEffect(self)
            shad.setBlurRadius(5)
    
            self.scene = QtGui.QGraphicsScene(self)
            self.view = QtGui.QGraphicsView(self)
            self.view.setScene(self.scene)
            text = self.scene.addText("Drop Shadow!")
            text.setGraphicsEffect(shad)
    
            layout.addWidget(self.view)
    
    if __name__ == "__main__":
        app = QtGui.QApplication([])
        main = Graphics()
        main.show()
        main.raise_()
        app.exec_()
    
    0 讨论(0)
  • 2021-01-14 22:47

    Works for me in C++. I did the following in a QDialog containing a QLabel object named titleLabel. I'm using Qt 4.8.4 on a Windows XP computer.

    QGraphicsDropShadowEffect* eff = new QGraphicsDropShadowEffect(this);
    eff->setBlurRadius(5);
    titleLabel->setGraphicsEffect(eff);
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题