QAction Disabled Problem



  • I would like to disable an action with an ask, in a slot

    void CMainWindow::warnDisableMyAct()//this is a slot
    {
    	QMessageBox::StandardButton ans = QMessageBox::question(this, tr("close tips"),tr("Are you sure to close this function?"));
    	bool isClose = (ans == QMessageBox::Yes);
    	myAct->setDisabled(isClosed);
        //bool isEnabled=myAct->isEnabled();
    }
    
        when I choose Yes in message box ,isEnabled is false ,but the relevent toolbar and menu is still visible and can be clicked.
        I try to call repaint(),update() of this window,but nothing different happend. 
        And if I don't ask any more,myAct can be disabled,
    
    void CMainWindow::warnDisableMyAct()//this is a slot
    {
    	myAct->setDisabled(true);
    }
    
       It seems that  setDisabled can't be called in selective structure and it's parameter must be a definitized value. Is anyone meet this situation?


  • Not sure it's the mistake but in bool isClose and setDisabled(isClosed) , you used different variables ( i'm sure you only wrote it wrong here )

    And is it the same thing with you using comment slashes here //bool isEnabled=myAct->isEnabled(); ?



  • Yes, I post a wrong code, the right code is

    void CMainWindow::warnDisableMyAct()//this is a slot
    {
        QMessageBox::StandardButton ans = QMessageBox::question(this, tr("close tips"),tr("Are you sure to close this function?"));
        bool isClose = (ans == QMessageBox::Yes);
        myAct->setDisabled(isClose);
        //bool isEnabled=myAct->isEnabled();
    }
    

    and the comment code here is just for debug, it doesn't matter if it is called.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.