Hi!
If I have QMainWindow I can rewrite
void CEditor::closeEvent(QCloseEvent *event) {
and return event->ignore(); to avoid closing.
How can I do something similar if I have a QDialog? (user press X button or hit ESC)
Thanks.
Hi!
If I have QMainWindow I can rewrite
void CEditor::closeEvent(QCloseEvent *event) {
and return event->ignore(); to avoid closing.
How can I do something similar if I have a QDialog? (user press X button or hit ESC)
Thanks.
closeEvent() is for all widgets, not just main window..so it should work with dialog too..if it doesnt, try setting window modality for dialog to true..that way it will become a TLW(top level widget), and closeEvent() would most certainly come to dialog
ricardo (11th May 2009)
It seems if I rewrite
void CSequencesDialog::closeEvent(QCloseEvent *event) {
works, but if I try to write
event->accept();
Or
event->ignore();
[/code]
1>.\CSequencesDialog.cpp(475) : error C2027: use of undefined type 'QCloseEvent'
1> c:\qt\2009.01\qt\include\qtgui\../../src/gui/kernel/qwidget.h(83) : see declaration of 'QCloseEvent'
1>.\CSequencesDialog.cpp(475) : error C2227: left of '->accept' must point to class/struct/union/generic type
1>.\CSequencesDialog.cpp(477) : error C2027: use of undefined type 'QCloseEvent'
1> c:\qt\2009.01\qt\include\qtgui\../../src/gui/kernel/qwidget.h(83) : see declaration of 'QCloseEvent'
1>.\CSequencesDialog.cpp(477) : error C2227: left of '->ignore' must point to class/struct/union/generic type
1>Build log was saved at "file://c:\Documents and Settings\Ricardo\Escritorio\iPhone\Kokochiko\Edito r\Editor\Debug\BuildLog.htm"
1>Editor - 4 error(s), 0 warning(s)
[code]
Any idea?
Bad news. I read this on Qt docs:
"If the user presses the Esc key in a dialog, QDialog::reject() will be called. This will cause the window to close: The close event cannot be ignored."
So, is that impossible?
Thanks.
May be you can try overriding QWidget::keyPressEvent or QWidget::keyReleaseEventand compare something like -
Qt Code:
if(event->key() == Qy::Key_Esc) event->ignore(); // or do nothing, dont call base call function for this caseTo copy to clipboard, switch view to plain text mode
Last edited by aamer4yu; 11th May 2009 at 06:33.
ricardo (11th May 2009)
I have a similar problem if I use keyPressEvent. It seems parameter is not recognized.
Qt Code:
>CSequencesDialog.cpp 1>.\CSequencesDialog.cpp(486) : error C2027: use of undefined type 'QKeyEvent' 1> c:\qt\2009.01\qt\include\qtgui\../../src/gui/kernel/qwidget.h(78) : see declaration of 'QKeyEvent' 1>.\CSequencesDialog.cpp(486) : error C2227: left of '->key' must point to class/struct/union/generic type 1>.\CSequencesDialog.cpp(486) : error C2653: 'Qy' : is not a class or namespace name 1>.\CSequencesDialog.cpp(486) : error C2065: 'Key_Esc' : undeclared identifier 1>.\CSequencesDialog.cpp(486) : error C2027: use of undefined type 'QKeyEvent' 1> c:\qt\2009.01\qt\include\qtgui\../../src/gui/kernel/qwidget.h(78) : see declaration of 'QKeyEvent' 1>.\CSequencesDialog.cpp(486) : error C2227: left of '->ignore' must point to class/struct/union/generic type 1>CEditor.cpp 1>Generating Code...To copy to clipboard, switch view to plain text mode
you forgot to include
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
ricardo (11th May 2009)
Thanks a lot, it worked.
Bookmarks