Results 1 to 6 of 6

Thread: prob in filter Esc key for dialog in a class

  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default prob in filter Esc key for dialog in a class

    This is my code

    Qt Code:
    1. void CommonFunctions::progressbar(QString Dialogtext)
    2. {
    3. layout = new QVBoxLayout;
    4. l = new QLabel( Dialogtext);
    5. l->setWordWrap(true);
    6. progress = new QProgressBar();
    7. progress->setWindowModality(Qt::WindowModal);
    8. progress->setRange(0,10);
    9. layout->addWidget(l);
    10. layout->addWidget(progress,Qt::AlignCenter);
    11. win->setMaximumWidth(320);
    12. win->setModal(true);
    13. win->setLayout(layout);
    14. win->setWindowTitle("title");
    15. installEventFilter(win);
    16. win->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint);
    17. win->show();
    18. }
    19.  
    20. bool QDialog::eventFilter(QObject *object, QEvent *event)
    21. {
    22. if (event->type() == QEvent::KeyPress) {
    23. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    24. if (keyEvent->key() == Qt::Key_Escape) {
    25. keyEvent->ignore();
    26. return true;
    27. } else
    28. return false;
    29. }
    30. return false;
    31. }
    To copy to clipboard, switch view to plain text mode 

    i had checked this code by setting a breakpoint in eventFilter(), while pressing Esc key debugger stops at break point and checks the condition in 22 line of the above code , but it fails & returns false

    where im getting wrong can anybody help me....

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: prob in filter Esc key for dialog in a class

    EDIT:
    events of which object do you want to filter?
    Last edited by high_flyer; 11th December 2009 at 10:16.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: prob in filter Esc key for dialog in a class

    try this ... but not sure
    win->installEventFilter(this);
    bool CommonFunctions::eventFilter()
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: prob in filter Esc key for dialog in a class

    i already tried with
    Qt Code:
    1. bool CommonFunctions::eventFilter()
    To copy to clipboard, switch view to plain text mode 
    but it gives error eventFilter() not a member of CommonFunctions

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: prob in filter Esc key for dialog in a class

    you have to add it to your header too!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: prob in filter Esc key for dialog in a class

    Quote Originally Posted by Askar View Post
    i already tried with
    Qt Code:
    1. bool CommonFunctions::eventFilter()
    To copy to clipboard, switch view to plain text mode 
    but it gives error eventFilter() not a member of CommonFunctions
    I think you should start from the beginning and learn some necessary C++ basics...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. need to filter Esc key for a dialog in a class
    By Askar in forum Qt Programming
    Replies: 6
    Last Post: 11th December 2009, 07:29
  2. QT Class GUI Interactions??
    By mikey33 in forum Newbie
    Replies: 3
    Last Post: 19th November 2009, 02:01
  3. Extending two class "the same way"
    By caduel in forum General Programming
    Replies: 3
    Last Post: 22nd July 2009, 22:55
  4. prob with QFile and QTextStream class
    By bajarangi in forum Newbie
    Replies: 0
    Last Post: 27th June 2009, 00:57
  5. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.