Results 1 to 20 of 30

Thread: Disable Close button (X) of a QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Disable Close button (X) of a QDialog

    Hello,

    I want to know if it is possible to disable the close button (X) of a QDialog during a Process.
    After my Process is finished i want to enable the close button (X) again.

    Posted some screenshots of an example to show what i mean.





    Any help is welcome

    Greetz,
    ..:: Still Standing Strong ::..

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    I didn't manage to do it by using the Qt window flags, but it is possible using winapi:
    Qt Code:
    1. #ifdef Q_WS_WIN
    2. CMenu* menu = this->GetSystemMenu(FALSE);
    3. menu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED );
    4. #endif
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    Marcel,
    this is not a Qt code. it is VC++ code.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    And what did I say?
    It's not VC code, but it is winapi code. Please notice the ifdefs.

  5. #5
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    BrainB0ne,

    try this:
    setWindowFlags(Qt::FramelessWindowHint);
    setWindowFlags(Qt::WindowTitleHint);

  6. The following user says thank you to rajesh for this useful post:

    ntp (3rd December 2007)

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    The second setWindowFlags overrides the first.
    And he said disable the button, not hide it. But I guess that's a solution too.

  8. #7
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    the first flag reset all flag to 0, so,it is also required.

  9. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    No.
    Using the second flag only yields the same result.
    setWindowFlags(Qt::WindowTitleHint) will result in the window flags to be JUST Qt::WindowTitleHint.

    If you want to set more than one flag you have to OR them:
    setWindowFlags(flag1 | flag2 | ... | flagn );

  10. #9
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    Damn i am really late with reacting.... sorry for that u guys.

    I am gonna try some of the solutions mentioned... i will tell you about what i have done
    ..:: Still Standing Strong ::..

  11. #10
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Exclamation Re: Disable Close button (X) of a QDialog

    hmmm... I dont get Marcel's solution to work with the Winapi code.

    And the next solution with the windowflags also doesnt work at Qt 3, the mentioned defines do not exist.

    Maybe i have to search trough the Qt 3 Assistent for appropriate window flags.

    Thx for your help and till next time
    ..:: Still Standing Strong ::..

  12. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    hmmm... I dont get Marcel's solution to work with the Winapi code.
    Do you get any errors or it just doesn't work?

    Maybe i have to search trough the Qt 3 Assistent for appropriate window flags.
    See http://doc.trolltech.com/3.3/qt.html#WidgetFlags-enum.
    Play with different combinations until you get some result. But it really depends on the window manager to respect the flags.

  13. #12
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by marcel View Post
    Do you get any errors or it just doesn't work?

    See http://doc.trolltech.com/3.3/qt.html#WidgetFlags-enum.
    Play with different combinations until you get some result. But it really depends on the window manager to respect the flags.

    With the Winapi code I first get the following errors:

    Qt Code:
    1. #ifdef Q_WS_WIN
    2.  
    3. CMenu* menu = m_pParent->GetSystemMenu(FALSE);
    4. menu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED );
    5.  
    6. #endif
    To copy to clipboard, switch view to plain text mode 
    : error C2065: 'CMenu' : undeclared identifier
    : error C2065: 'menu' : undeclared identifier
    : error C2039: 'GetSystemMenu' : is not a member of 'QWidget'
    : see declaration of 'QWidget'
    : error C2227: left of '->ModifyMenu' must point to class/struct/union
    : error C2065: 'SC_CLOSE' : undeclared identifier
    : error C2065: 'MF_BYCOMMAND' : undeclared identifier
    : error C2065: 'MF_GRAYED' : undeclared identifier


    After that i include the <afxwin.h> include file (for CMenu class)
    Then the following errors show up:
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(226) : warning C4005: 'ASSERT' : macro redefinition
    C:\Qt\3.3.4\include\qglobal.h(1010) : see previous definition of 'ASSERT'
    : error C2039: 'GetSystemMenu' : is not a member of 'QWidget'
    C:\Qt\3.3.4\include\qwidget.h(60) : see declaration of 'QWidget'
    ..:: Still Standing Strong ::..

  14. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable Close button (X) of a QDialog

    That's MFC, not WinAPI...
    Qt Code:
    1. #include <QtGui>
    2. #ifdef Q_WS_WIN
    3. #include <qt_windows.h>
    4. #endif // Q_WS_WIN
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. QWidget window;
    10.  
    11. #ifdef Q_WS_WIN
    12. HMENU menu = ::GetSystemMenu(window.winId(), FALSE);
    13. ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
    14. ::EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
    15. // or (removes the item in of system menu)
    16. // ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
    17. #endif // Q_WS_WIN
    18.  
    19. window.show();
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  15. The following user says thank you to jpn for this useful post:

    BrainB0ne (10th October 2007)

  16. #14
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by jpn View Post
    That's MFC, not WinAPI...
    Qt Code:
    1. #include <QtGui>
    2. #ifdef Q_WS_WIN
    3. #include <qt_windows.h>
    4. #endif // Q_WS_WIN
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. QWidget window;
    10.  
    11. #ifdef Q_WS_WIN
    12. HMENU menu = ::GetSystemMenu(window.winId(), FALSE);
    13. ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
    14. ::EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
    15. // or (removes the item in of system menu)
    16. // ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
    17. #endif // Q_WS_WIN
    18.  
    19. window.show();
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Woooow! That did the job! I'm really happy with this solution
    ..:: Still Standing Strong ::..

Similar Threads

  1. Diasble close button on a QDialog
    By Krish_ng in forum Qt Programming
    Replies: 12
    Last Post: 17th July 2007, 04:23
  2. Replies: 1
    Last Post: 7th July 2007, 09:03
  3. Disable Checkable Button Question
    By jbpvr in forum Qt Programming
    Replies: 9
    Last Post: 20th March 2007, 17:57
  4. Replies: 2
    Last Post: 5th February 2007, 17:42
  5. Replies: 3
    Last Post: 16th November 2006, 12:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.