Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gray out a menu item in Qt

Tags:

c++

qt

menu

I'm building a small program in Qt with menu bars (menuBar) using C++ and I would like to know how to gray out (eg. disable) an item of the menu when a certain variable is activated. Is it possible?

like image 955
user1031431 Avatar asked Feb 29 '12 21:02

user1031431


1 Answers

If you know an index of the corresponding QAction :

QMenu::actions.at(i).setEnabled(false);

P.S. As kindly prompted below, setEnabled(bool) and setDisabled(bool) are slots (so is toggle()), so they can be connected to a signal indicating a need to change the availability of the action.

like image 191
Dmitriy Kachko Avatar answered Sep 24 '22 19:09

Dmitriy Kachko