Search code examples
pythonpyqtpyqt4

How can I gray out a menu item in PyQt


I'm building a program in PyQt where a user can choose from a set of selectable menu items. However, I want the user to only be able to click on things when certain conditions have been met. What I would like to know is, is it possible to gray out or completely disable an item in the menu area?


Solution

  • It is possible to do something like this.

    use setDisabled to do this.
    Here is an example of this working.
    The parameter is a boolean, and setting it to True will make your object grey out.

    self.FooBarMenuItem.setDisabled(True)
    

    enter image description here


    to turn it off, simply set the parameter's value to False

    self.FooBarMenuItem.setDisabled(False)
    

    enter image description here


    You can also make items completely disappear by using the setVisible function
    self.FooBarMenuItem.setVisible(False)
    

    enter image description here