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. How to toggle WindowCloseButton Hint off and on
Forum Updated to NodeBB v4.3 + New Features

How to toggle WindowCloseButton Hint off and on

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.0k 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.
  • A Offline
    A Offline
    AaronKelsey
    wrote on last edited by
    #1

    I am wanting to disable the close window button on a QDialog until a process has finished, I want to disable and enable the button using a boolean as a toggle.

    I have written this function but unfortunately I am having no luck. I saw that when I change the window flags it it calls setParent which hides the dialog, but when using show() to reshow the dialog once hidden the application stops responding and I cannot work out what I have done wrong.

    void NodeLogDialog::enableButtons(bool bEnabled)
    {
    	ui->btnOK->setEnabled(bEnabled);
    	ui->btnSave->setEnabled(bEnabled);
    
    	Qt::WindowFlags flags = this->windowFlags();
    
    	if (bEnabled)
    	{
    		setWindowFlags(windowFlags() | (Qt::WindowContextHelpButtonHint) | (Qt::WindowCloseButtonHint));
    	}
    	else
    	{
    		setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint) & (~Qt::WindowCloseButtonHint));
    	}
    
    	show();
    }
    

    Thank you in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      What OS are you running ?
      When/How is that method called in your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What version of Qt are you using ?
        What OS are you running ?
        When/How is that method called in your application ?

        A Offline
        A Offline
        AaronKelsey
        wrote on last edited by
        #3

        @SGaist

        Hey,

        I am using QT 5.1.0 and I am running Windows 10 Enterprise.

        I create a node dialog object and then call exec from my main window class.

        NodeLogDialog oNodeLogDialog(moSuppMgrHubAddress,
                                            oSelectedNodes,
                                            this);
        
        oNodeLogDialog.exec();
        

        The code below is a function within NodeLogDialog.

        void NodeLogDialog::enableButtons(bool bEnabled)
        {
        	ui->btnOK->setEnabled(bEnabled);
        	ui->btnSave->setEnabled(bEnabled);
        
        	Qt::WindowFlags flags = this->windowFlags();
        
        	if (bEnabled)
        	{
        		setWindowFlags(windowFlags() | (Qt::WindowContextHelpButtonHint) | (Qt::WindowCloseButtonHint));
        	}
        	else
        	{
        		setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint) & (~Qt::WindowCloseButtonHint));
        	}
        
        	show();
        }
        
        jsulmJ 1 Reply Last reply
        0
        • A AaronKelsey

          @SGaist

          Hey,

          I am using QT 5.1.0 and I am running Windows 10 Enterprise.

          I create a node dialog object and then call exec from my main window class.

          NodeLogDialog oNodeLogDialog(moSuppMgrHubAddress,
                                              oSelectedNodes,
                                              this);
          
          oNodeLogDialog.exec();
          

          The code below is a function within NodeLogDialog.

          void NodeLogDialog::enableButtons(bool bEnabled)
          {
          	ui->btnOK->setEnabled(bEnabled);
          	ui->btnSave->setEnabled(bEnabled);
          
          	Qt::WindowFlags flags = this->windowFlags();
          
          	if (bEnabled)
          	{
          		setWindowFlags(windowFlags() | (Qt::WindowContextHelpButtonHint) | (Qt::WindowCloseButtonHint));
          	}
          	else
          	{
          		setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint) & (~Qt::WindowCloseButtonHint));
          	}
          
          	show();
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AaronKelsey said in How to toggle WindowCloseButton Hint off and on:

          void NodeLogDialog::enableButtons(bool bEnabled)

          Where do you call it?
          Keep in mind that exec() is a blocking call, so you need to call that method before exec().

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @AaronKelsey said in How to toggle WindowCloseButton Hint off and on:

            void NodeLogDialog::enableButtons(bool bEnabled)

            Where do you call it?
            Keep in mind that exec() is a blocking call, so you need to call that method before exec().

            A Offline
            A Offline
            AaronKelsey
            wrote on last edited by
            #5

            @jsulm I call this function twice after I call exec(). If exec is a blocking call what method can I use to get around this? Whilst the dialog is open using exec I need to disable and enable the buttons.

            jsulmJ 1 Reply Last reply
            0
            • A AaronKelsey

              @jsulm I call this function twice after I call exec(). If exec is a blocking call what method can I use to get around this? Whilst the dialog is open using exec I need to disable and enable the buttons.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AaronKelsey Initially you can call it just before exec().
              Afterwards you can use signals/slots to let the dialog know that you want to enable/disable buttons.
              But I'm wondering what the trigger is (or who calls it then) after exec() as that one is blocking?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @AaronKelsey Initially you can call it just before exec().
                Afterwards you can use signals/slots to let the dialog know that you want to enable/disable buttons.
                But I'm wondering what the trigger is (or who calls it then) after exec() as that one is blocking?

                A Offline
                A Offline
                AaronKelsey
                wrote on last edited by
                #7

                @jsulm I am not sure whether I have fully understood your question but the toggle for enabling/disabling the dialog close button is handled and called within the dialog class.

                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