Results 1 to 3 of 3

Thread: Avoid MainWindow from closing

  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Avoid MainWindow from closing

    Hi guys, I`ve reading the documentation with no luck...

    I have a MainWindow with a menuBar and only one QToolButton that closes the mainWindow (as a result the application)..The thing is that when the spacebar is pressed within the mainWindow context, as the close button is the only one there, it triggers closing the application. So far I have this code but it seems that it is not intercepting the signal of the spacebar:

    Qt Code:
    1. void MainWindow::keyPressEvent (QKeyEvent *event){
    2. if (event == new QKeyEvent (QEvent::KeyPress, 20,0)){
    3. event->ignore ();
    4. }
    5. else{
    6. event->accept ();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance!

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Avoid MainWindow from closing

    Qt Code:
    1. QToolButton button ;
    2.  
    3. button.setFocusPolicy( Qt::ClickFocus ) ; // explicitly set widget's focus policy : " the widget accepts focus by clicking. ". Look at the QWidget::setFocusPolicy function description
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to AlexSudnik for this useful post:

    KillGabio (14th February 2012)

  4. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Avoid MainWindow from closing

    Thanks Alex

Similar Threads

  1. Replies: 0
    Last Post: 6th November 2011, 10:22
  2. Replies: 2
    Last Post: 28th June 2011, 15:09
  3. Replies: 1
    Last Post: 12th April 2011, 10:53
  4. how to avoid crash of my application......
    By newb in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 11:09
  5. Closing all of the mainWindow's child dialogs
    By JPNaude in forum Qt Programming
    Replies: 4
    Last Post: 2nd October 2008, 14:18

Tags for this Thread

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.