Change the reject or close event in Qdialog
-
Hello,
I need to change the reject or close event in a QDialog, I need to hide the Qdialog when the X button on the frame it's press, but to close the window when the reject or close method it's call in the window.
Can someone give me some inside in to how to do this or any other idea to this ??
Thanks
-
When X button is clicked it is normal behavior that QDialog is hidden.
"reject or close method it's call in the window." - does not make sense.It is not clear what you want to do.
This is not an offense but to give any advice people need to understand what you want to achieve.What happens in QWidget derived classes is defined in
void QWidget::closeEvent(QCloseEvent *event)You can override it in your class to control what happens like below:
void MainWindow::closeEvent(QCloseEvent *event)
{
if (maybeSave()) {
writeSettings();
event->accept();
} else {
event->ignore();
}
} -
I'm sorry If I didn't explain myself, but when I push the X button of the QDialog the QDialog closes and the application too.
What I need it's to close the QDialog only when I call the reject() or accept() method in my code and to hide the QDialog in the trayIcon when the X button it's press.
I don't know how to explain this better.
-
I'm sorry If I didn't explain myself, but when I push the X button of the QDialog the QDialog closes and the application too.
What I need it's to close the QDialog only when I call the reject() or accept() method in my code and to hide the QDialog in the trayIcon when the X button it's press.
I don't know how to explain this better.
@SujaMM As @alex_malyu explained you need to override closeEvent to handle operation when close button is clicked.
To minimize it to tray, use QSystemTrayIcon. Check out the example here.