PDA

View Full Version : Avoid MainWindow from closing



KillGabio
14th February 2012, 15:20
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:


void MainWindow::keyPressEvent (QKeyEvent *event){
if (event == new QKeyEvent (QEvent::KeyPress, 20,0)){
event->ignore ();
}
else{
event->accept ();
}
}


Thanks in advance!

AlexSudnik
14th February 2012, 16:11
QToolButton button ;

button.setFocusPolicy( Qt::ClickFocus ) ; // explicitly set widget's focus policy : " the widget accepts focus by clicking. ". Look at the QWidget::setFocusPolicy function description

KillGabio
14th February 2012, 16:55
Thanks Alex :D