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.
http://img233.imageshack.us/img233/1...enabledle2.jpg
http://img233.imageshack.us/img233/3...isabledaa3.jpg
Any help is welcome :)
Greetz,
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:
Code:
#ifdef Q_WS_WIN
CMenu* menu = this->GetSystemMenu(FALSE);
menu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED );
#endif
Re: Disable Close button (X) of a QDialog
Marcel,
this is not a Qt code. it is VC++ code.
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.
Re: Disable Close button (X) of a QDialog
BrainB0ne,
try this:
setWindowFlags(Qt::FramelessWindowHint);
setWindowFlags(Qt::WindowTitleHint);
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.
Re: Disable Close button (X) of a QDialog
the first flag reset all flag to 0, so,it is also required.
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 );
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 :)
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 :)
Re: Disable Close button (X) of a QDialog
Quote:
hmmm... I dont get Marcel's solution to work with the Winapi code.
Do you get any errors or it just doesn't work?
Quote:
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.
Re: Disable Close button (X) of a QDialog
Quote:
Originally Posted by
marcel
With the Winapi code I first get the following errors:
Code:
#ifdef Q_WS_WIN
CMenu* menu = m_pParent->GetSystemMenu(FALSE);
menu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED );
#endif
: 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'
Re: Disable Close button (X) of a QDialog
That's MFC, not WinAPI... ;)
Code:
#include <QtGui>
#ifdef Q_WS_WIN
#include <qt_windows.h>
#endif // Q_WS_WIN
int main(int argc, char *argv[])
{
#ifdef Q_WS_WIN
HMENU menu = ::GetSystemMenu(window.winId(), FALSE);
::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
::EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
// or (removes the item in of system menu)
// ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
#endif // Q_WS_WIN
window.show();
return app.exec();
}
Re: Disable Close button (X) of a QDialog
Quote:
Originally Posted by
jpn
That's MFC, not WinAPI... ;)
Code:
#include <QtGui>
#ifdef Q_WS_WIN
#include <qt_windows.h>
#endif // Q_WS_WIN
int main(int argc, char *argv[])
{
#ifdef Q_WS_WIN
HMENU menu = ::GetSystemMenu(window.winId(), FALSE);
::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
::EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
// or (removes the item in of system menu)
// ::DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
#endif // Q_WS_WIN
window.show();
return app.exec();
}
Woooow! That did the job! :D I'm really happy with this solution :D :cool:
Re: Disable Close button (X) of a QDialog
Hi guys,
I'm quite late on this thread but I had the same problem :-)
Anybody knows how to disable that nasty little button on X11 and Mac OS X??
In case you need it, here is a nice macro I am using on Win32 - it's pretty similar to the latest post of course and it works fine:
Code:
# ifdef Q_OS_WIN
# include <windows.h>
# define ENABLE_CLOSE_BTN(Enable) \
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
Now just use ENABLE_CLOSE_BTN(true) or ENABLE_CLOSE_BTN(false).
It will detect the top level widget of the widget containing the code, so you can use it inside of a child widget (eg. a wizard page in my case) without having to change the macro :D
Feel free to replace that "while" loop if you are always going to use it inside of a top level window.
And now on with your suggestions for X11/MAC ;)
Re: Disable Close button (X) of a QDialog
How do I hide close, resize and minimize featuers in QGLWidget??
Code:
setWindowFlags(Qt::FramelessWindowHint);
does not work!!
Re: Disable Close button (X) of a QDialog
Quote:
Originally Posted by
MarkoSan
How do I hide close, resize and minimize featuers in QGLWidget??
Code:
setWindowFlags(Qt::FramelessWindowHint);
does not work!!
What do you mean? Are you showing QGLWidget as a top level window? QGLWidget is a QWidget so when it comes to adjusting window flags, anything that works for a plain QWidget should work with QGLWidget as well.
Re: Disable Close button (X) of a QDialog
Quote:
Originally Posted by
blue.death
Hi guys,
I'm quite late on this thread but I had the same problem :-)
Anybody knows how to disable that nasty little button on X11 and Mac OS X??
In case you need it, here is a nice macro I am using on Win32 - it's pretty similar to the latest post of course and it works fine:
Code:
# ifdef Q_OS_WIN
# include <windows.h>
# define ENABLE_CLOSE_BTN(Enable) \
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
Now just use ENABLE_CLOSE_BTN(true) or ENABLE_CLOSE_BTN(false).
It will detect the top level widget of the widget containing the code, so you can use it inside of a child widget (eg. a wizard page in my case) without having to change the macro :D
Feel free to replace that "while" loop if you are always going to use it inside of a top level window.
And now on with your suggestions for X11/MAC ;)
Woo so good! thx for the nice macro! its works just nice :p
Re: Disable Close button (X) of a QDialog
Starting with Qt 4.5 there is a new window hint for controlling close button Qt::WindowCloseButtonHint:
Code:
w.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint| Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonHint);
Re: Disable Close button (X) of a QDialog
Quote:
Originally Posted by
shad
Starting with Qt 4.5 there is a new window hint for controlling close button Qt::WindowCloseButtonHint:
Code:
w.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint| Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonHint);
That's very nice to hear/know when i'm going to use Qt 4.5 or higher in the future! :)