If me press Escape button then dialog will close. How to prevent it ? I must installEventFilter to every widget ?
If me press Escape button then dialog will close. How to prevent it ? I must installEventFilter to every widget ?
you mast read abut QDialog first of all.
after that i can suggest you to reimplement void QDialog::reject() [protected]
like this
Qt Code:
... void reject() { //nothing :) } ...To copy to clipboard, switch view to plain text mode
east or west home is best
"If me press Escape button then dialog will close. How to prevent it ? I must installEventFilter to every widget ?"
You can make new class , say MyQtDialog then reimplement keyPressEvent there like
this :
Qt Code:
{ Q_OBJECT; ..... { if(e->key() == Qt::Key_Escape) return; } }To copy to clipboard, switch view to plain text mode
Then use this class as base class for all dialog classes.
I'm not create new class for QDialog, but I reimplement keyPressEvent in protected. And works now
kwisp,
Without installEventFilter and reimplement reject(), all close function can't work anymoreThis is amazing
![]()
wirasto,
i do not understand you![]()
east or west home is best
I think he means keyPressEvent is virtual protected, and he has overrode its function. It's a standard thing to do in Qt land.
i use eventFilter and installEventFilter becouse at begining this topick had very special question -- how to disable ALT+F4(Close window by X-button in top right coner and do not close by ALT+F4) i dont know realy why author whant this... he asked - i answer.
How to disable Key_Escape in QDialog? -- It is another question. Key_Escape is special key for QDialog. It is meaning -- QDialog::reject(). And i intend that if we whant not close dialog by reject we must write subclass(class MDialog: public QDialog) and reimplement virtual slot: void reject().
But this disable button "Cancel" and X-button.
If we whant to close dialog by "Cancel"-button and X-button, and do not close by Escape(i realy do not know what for) -- It is necessary to brain scatter.![]()
east or west home is best
hi,
is this piece of code worked for any of you guys?
//
.....
case QEvent::KeyPress: {
if(((QKeyEvent*)event)->key() == Qt::Key_F4 || (((QKeyEvent*)event)->modifiers() == Qt::AltModifier)) {
...........
//
I think "||" should be "&&".
Any way thats not important, what important is is this key sequence creating the close event that can be caught?
What i feel, its not taking the control to the code put with in such condition and the widget is being closed directly?
Could any one give a clear picture of catching the event created by Alt + F4?
Edit: Its creates a closeEvent(). but can we catch the key press like above?
Last edited by netmat; 22nd June 2010 at 15:00.
Alt+F4 is a special key sequence (like Ctrl-Alt-Del), I don't think you can trap it without writing a driver. You can however (as stated above) trap the resulting close event.
It is a good idea in general to keep standard key combinations working in your program. It helps making your program easier to use by decreasing the learning curve.
Horse sense is the thing that keeps horses from betting on people. --W.C. Fields
Ask Smart Questions
Bookmarks