Results 1 to 20 of 20

Thread: How to disable ALT + F4

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: How to disable ALT + F4

    I was looking to find the same , but can't find it.
    I am sure there is must some way to say if ALT +F4 was pressed

  2. #2
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: How to disable ALT + F4

    I try the following , but not working :

    Qt Code:
    1. bool MyDlg::event(QEvent *event)
    2. {
    3. QKeyEvent* myKeyEvent=(QKeyEvent*)event;
    4. if(myKeyEvent->matches(QKeySequence::Close))
    5. return true;
    6. return QDialog::event(event);
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: How to disable ALT + F4

    see my "crutch" example you can simplify it
    Qt Code:
    1. #include <QApplication>
    2. #include <QUrl>
    3. #include <QVariant>
    4. #include <QString>
    5. #include <QtGlobal>
    6. #include <QDebug>
    7. #include <QWidget>
    8. #include <QKeyEvent>
    9. #include <QCloseEvent>
    10. #include <QMouseEvent>
    11. #include <QEvent>
    12.  
    13. class CloseHandler:public QObject {
    14. private:
    15. bool flag;
    16. protected:
    17. bool eventFilter(QObject* obj, QEvent* event)
    18. {
    19. if(obj->isWidgetType()) {
    20. switch(event->type()) {
    21. case QEvent::Close: {
    22. qDebug()<<__func__<<"Close";
    23. if(flag){
    24. event->ignore();
    25. return true;
    26. }
    27. //flag = false;
    28. break;
    29. }
    30. case QEvent::KeyPress: {
    31. if(((QKeyEvent*)event)->key() == Qt::Key_F4 || (((QKeyEvent*)event)->modifiers() == Qt::AltModifier)) {
    32. flag = true;
    33. }
    34. break;
    35. }
    36. case QEvent::MouseButtonPress://??
    37. case QEvent::MouseButtonRelease://??
    38. case QEvent::MouseMove://??
    39. case QEvent::Leave://!!
    40. flag = false;
    41. default: break;
    42. }
    43. }
    44. return QObject::eventFilter(obj,event);
    45. }
    46. };
    47.  
    48. int main(int a ,char** b )
    49. {
    50. QApplication app(a,b);
    51. CloseHandler h;
    52. w.installEventFilter(&h);
    53. w.show();
    54. return app.exec();
    55. }
    To copy to clipboard, switch view to plain text mode 
    east or west home is best

  4. The following 2 users say thank you to kwisp for this useful post:

    elizabeth.h1 (16th October 2009), Olumide (12th December 2013)

  5. #4
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    20
    Thanked 5 Times in 5 Posts

    Question Re: How to disable ALT + F4

    How to disable escape key too ? I modified your code, but not work

    Qt Code:
    1. case QEvent::KeyPress:
    2. {
    3. if (((QKeyEvent*)event)->key() == Qt::Key_F4 || (((QKeyEvent*)event)->modifiers() == Qt::AltModifier))
    4. {
    5. flag = true;
    6. }
    7.  
    8. //this is my code
    9. if (((QKeyEvent*)event)->key() == Qt::Key_Escape) {
    10. flag =true;
    11. }
    12.  
    13. break;
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to disable keyboard
    By garry_3peace in forum Newbie
    Replies: 9
    Last Post: 27th October 2009, 04:17
  2. how to disable OnItem drops in a QListView?
    By rgl in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2009, 15:26
  3. How to disable NextButton in QWizard ?
    By litroncn in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2008, 07:05

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
  •  
Qt is a trademark of The Qt Company.