Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAction Disabled Problem
Qt 6.11 is out! See what's new in the release blog

QAction Disabled Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 956 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0odiuo00 Offline
    0odiuo00 Offline
    0odiuo0
    wrote on last edited by 0odiuo0
    #1

    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?
    
    1 Reply Last reply
    0
    • W Offline
      W Offline
      Walux
      wrote on last edited by Walux
      #2

      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(); ?

      Taking things from beginning to end : That's my entertainment !

      1 Reply Last reply
      0
      • 0odiuo00 Offline
        0odiuo00 Offline
        0odiuo0
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved