Hide & Show QWidget in closeEvent with Keyboard key
-
Hello,
My goal is to let the user decide in the closeEvent whether to hide the window or not. And if with window is hidden the window can be shown using a keyboard shortcut again.
What I've done so far:
Header:
protected:
void closeEvent(QCloseEvent *event);Source:
void Widget::closeEvent(QCloseEvent *event)
{
QMessageBox::StandardButton dialog;
dialog = QMessageBox::warning(this, "Close?",
"Do you want to close the Window?\nElse it will be hidden!\nShow using INSERT key",
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (dialog == QMessageBox::Yes)
this->close();
else if (dialog == QMessageBox::No)
this->hide();
else
event->ignore();
}Now I'm trying to find a way to show the window again using a keyboard hook...
Thanks in advance
-
Hi,
Do you mean you are hiding the main window of your application or a sub-window ?
-
Actually I have just one Window and in the closeEvent and I want the user to decide whether to close or hide it which works fine...
But once the window is hidden there is no other window opened at that time. So in order to show it back I want to use a keyboard shortcut like "INSERT". I've already tried KeyEvent but it only works if the window is visible... I hope it's more clear now -
Are you using a QSystemTrayIcon so that user has a possibility to get the window back ?
-
You're welcome !
As for marking the thread as solved, you can now use the "Topic Tool" button, it will keep the title clean.
Also, while browsing the forum, please consider up-voting answers that helped you, that will make them easier to find for other forum users :)