Are you sure? Come on! Are you serious? Do you really want to quit the application and have a real life? 

 

Lately I was looking for a way to disable that nifty little close (X) button on a window title bar. There is no way to do this using Qt code so I had to write my own platform dependant code.

This is the macro I am using on Windows:

# ifdef Q_OS_WIN
#  include <windows.h>
#  define ENABLE_CLOSE_BTN(Enable) \
    { QWidget* tlw = this; \
    while (tlw && !tlw->isWindow() && tlw->windowType() != Qt::SubWindow) \
        tlw = tlw->parentWidget(); \
    HMENU hMenu = GetSystemMenu((HWND) tlw->winId(), FALSE); \
    EnableMenuItem(hMenu, SC_CLOSE, Enable ? (MF_BYCOMMAND | MF_ENABLED) : (MF_BYCOMMAND | MF_GRAYED)); }
# endif // Q_OS_WIN

The macro can be used from any widget (e.g. a QWizardPage) as it will automatically look for the parent top level widget.

I still haven’t found a way to achieve the same on X11 or Mac OS X. Any suggestions? Anyone reading this blog? No? Rats, I knew that!