문제

I would like to make a Subclass of QLabel that acts as a boolean toggle button. I would like to be able to assign any pixmap, and have the image be desaturated when the button state is False. I am guessing this could be done with QColor somehow, but am not really sure how I would implement this. Any Ideas?

도움이 되었습니까?

해결책

You should be able to do what you want using QGraphicsColorizeEffect:

    self.label = QtGui.QLabel(self)
    effect = QtGui.QGraphicsColorizeEffect(self.label)
    effect.setStrength(0.0)
    effect.setColor(QtGui.QColor('silver'))
    self.label.setGraphicsEffect(effect)

To toggle the effect, set the strength as appropriate:

    if self.label.graphicsEffect().strength():
        self.label.graphicsEffect().setStrength(0.0)
    else:
        self.label.graphicsEffect().setStrength(0.5)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top