[PyQt] make an icon disabled while keeping it checked

TP paratribulations at free.fr
Wed Jun 17 10:34:57 BST 2009


Hi everybody,

It seems that it is impossible to keep an icon checked and make it disabled
with the styles other than the "Windows" one. Try the following example
which uses the "Plastique" style. Check the blue icon, and then check on
the "modif" button. The blue icon becomes unchecked on my machine, while it
should remain checked.
Now change the style from "Plastique" to "Windows". Run the script again.
This time it works.
It does work neither in "Cleanlooks", nor in "Motif", "CDE" styles.

I have tested it on two machines:
* Linux machine, Qt 4.4.0, PyQt 4.4.4
* Windows machine, Qt 4.4.1, PyQt 4.4.3

The result is the same.
Is the bug corrected in a more recent version of Qt?

Thanks a lot

Julien


####################
#!/usr/bin/python

# toolbar.py

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.resize(250, 150)
        self.setWindowTitle('toolbar')

        self.pixi = QPixmap(20,20)
        self.pixColor = Qt.blue
        self.pixi.fill (self.pixColor)
        icon = QIcon(self.pixi)

        self.tool = QAction(icon, 'Color', self)
        self.tool.setCheckable(True)



        self.toolbar = self.addToolBar('Color')
        self.toolbar.addAction(QIcon(), 'modif', self.modif)
        self.toolbar.addAction(self.tool)


    def modif(self):
        self.tool.setEnabled(not(self.tool.isEnabled()))





app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("Plastique"))
main = MainWindow()
main.show()
sys.exit(app.exec_())
#################

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the PyQt mailing list