On/Off-Switch with QPushButton

Rainer Dorsch ml at bokomoko.de
Sun Nov 1 10:15:21 UTC 2015


Hello,

I wrote a plasmoid a number of QPushButtons with an (svg) QIcon each. Every 
button controls a switch which has an "on" and an "off" state. The button is 
used to control and show the state of the switch.

Works nicely, my current implementation has two icons which it sets to signal 
the state of the switch. This requires two svgs though.

In addition, I used colored text to signal the state with the 
QPushButton:

    def modifyButton(self, number,state):
        self.button[number].setIcon(QIcon(prefix+icons[number][state]))
        self.button[number].setText(device[number])
        if state == 0:
            self.button[number].setStyleSheet("color: rgb(255, 0, 0);");
        else:
            self.button[number].setStyleSheet("color: rgb(0, 255, 0)");


The downside here is that the QIcon is not scaled:

	http://netcup.bokomoko.de/~rd/plasma-plug.png

I tried to add buttonSet[number].setIconSize(x,y)

    def modifyButton(self, number,state):
        self.button[number].setIcon(QIcon(prefix+icons[number][state]))
        self.button[number].setIconSize(QSize(100,100))
        self.button[number].setText(device[number])
        if state == 0:
            self.button[number].setStyleSheet("color: rgb(255, 0, 0);");
        else:
            self.button[number].setStyleSheet("color: rgb(0, 255, 0)");

this results in an AttributError though

AttributeError: 'PushButton' object has no attribute 'setIconSize'

Interesting enough the size issue is then gone...

I am almost sure there are much more elegant solutions for this issue. Can 
anybody give advice?

Many thanks
Rainer
        
-- 
Rainer Dorsch
http://bokomoko.de/


More information about the Plasma-devel mailing list