pelos
pelos

Reputation: 1876

pyqt changing the color of a button when pressed using a stylesheet

i am trying to change the color of a button when is press, and look like it can be done directly with in the stylesheet with out to do a function and then connect it.

in http://qt.developpez.com/doc/4.7-snapshot/stylesheet-examples/ show this example:

QPushButton#evilButton {
    background-color: red;
    border-style: outset;
    border-width: 2px;
    border-radius: 10px;
    border-color: beige;
    font: bold 14px;
    min-width: 10em;
    padding: 6px;
}
QPushButton#evilButton:pressed {
    background-color: rgb(224, 0, 0);
    border-style: inset;
}

how can translate that to python pyqt?

Upvotes: 6

Views: 29770

Answers (3)

zerocode
zerocode

Reputation: 31

self.button.setStyleSheet('background-color:#FFFFFF;color:#000000;')    

nameofbutton.setStyleSheet('background-color:#FFFFFF;color:#000000;')   

Upvotes: 3

pelos
pelos

Reputation: 1876

i was able to make it work like this, that way the color button is blue and when is press changes to red

    btn_text = QString("this font color")
    btn = QPushButton(btn_text)

    btn.setStyleSheet("QPushButton { background-color: blue }"
                      "QPushButton:pressed { background-color: red }" )

Upvotes: 11

Oliver
Oliver

Reputation: 29493

No translation needed, it is a stylesheet: a text document used by qt (and therefore by pyqt, since pyqt calls qt). For example:

self.groupBox.setStyleSheet("""
       QGroupBox 
       { 
           background-color: rgb(255, 255,255); 
           border:1px solid rgb(255, 170, 255); 
       }
       """
)

Take a look at http://vimeo.com/50033293.

Upvotes: 6

Related Questions