PDA

View Full Version : Can't disable a QAction in QMenu



punkypogo
10th August 2010, 10:41
Hi,

I have few QActions added to a QMenu:
ui->menuView->addAction( pAction1 );
ui->menuView->addAction( pAction2 );
ui->menuView->addAction( pAction3 );

My problem is that I can't disable a particular QAction:
pAction2->setDiasbled( true ); // doesn't do anything

In the documentation it is written: "An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible."
So why it doesn't work makes sense, but it is not what I want.

How can I do it?

Thanks.

aamer4yu
10th August 2010, 10:55
What error are you getting ?

pAction2->setDiasbled( true );
is that typo here ? it should be setDisabled.... spelling mistake

punkypogo
10th August 2010, 12:08
Sorry, spelling mistake. Compiling is ok, no output message in the console, nothing happens : the QAction's text is not grayed and can still be triggered.

tsp
10th August 2010, 15:07
I use QAction::setEnabled without problems (disabled is inline method for !enabled), are you sure that the piece of code that disables pAction2 is executed? Add qDebug in front of the line and see whether that trace is printed.