Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Hide & Show QWidget in closeEvent with Keyboard key
QtWS25 Last Chance

Hide & Show QWidget in closeEvent with Keyboard key

Scheduled Pinned Locked Moved Solved General and Desktop
hidewindowkeyboardcloseeventqwidget
8 Posts 2 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pusheax
    wrote on 22 Nov 2015, 00:39 last edited by SGaist
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Nov 2015, 22:22 last edited by
      #2

      Hi,

      Do you mean you are hiding the main window of your application or a sub-window ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pusheax
        wrote on 23 Nov 2015, 19:25 last edited by
        #3

        Hey,

        I'm hiding the MainWindow of my application. Hiding the Window is no problem but showing it again with a keyinput is the problem...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Nov 2015, 20:40 last edited by
          #4

          Do you want that from another part of your application ? If so you can use e.g. QShortcut

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pusheax
            wrote on 23 Nov 2015, 20:58 last edited by
            #5

            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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 23 Nov 2015, 21:50 last edited by
              #6

              Are you using a QSystemTrayIcon so that user has a possibility to get the window back ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pusheax
                wrote on 25 Nov 2015, 20:18 last edited by
                #7

                Thanks you so much for the idea :D The problem is solved, I simply implemented a QSystemTrayIcon :)!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 25 Nov 2015, 21:25 last edited by
                  #8

                  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 :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  8/8

                  25 Nov 2015, 21:25

                  • Login

                  • Login or register to search.
                  8 out of 8
                  • First post
                    8/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved