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 a QDialog
Forum Updated to NodeBB v4.3 + New Features

Hide a QDialog

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 14.1k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Chuck Gao
    wrote on last edited by
    #2

    If you create a dialog(specially subclass of QDialog), it won't show until the show() or exec() called.

    Yes, you can use timer to handle this: hide for seconds, then show it :)

    Chuck

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JulienMaille
      wrote on last edited by
      #3

      Hum right. Let's say that I want the dialog to "start" hidden, and the either close it (so the user will never see it) or show it. Is there a way to do this?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #4

        Simply create an instance, and don't call show() on it?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #5

          Where is the code that "controls" the display behavior?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chuck Gao
            wrote on last edited by
            #6

            For dialog, if you want hide or delete it, you can just close it and delete.

            Do you want a floating widget, which display like a balloon tooltip, show some seconds then disappeared?

            Chuck

            1 Reply Last reply
            0
            • S Offline
              S Offline
              silver47
              wrote on last edited by
              #7

              MyDialog.h
              @
              #include <QDialog>
              class MyDialog : public QDialog
              {
              Q_OBJECT
              public:
              explicit MyDialog(QWidget *parent = 0);
              }
              @

              MyDialog.cpp
              @
              MyDialog::MyDialog(QWidget *parent) : QDialog(parent){
              }
              @

              You can "start dialog hidden":
              @dialog = new MyDialog();@
              Dialog is present, but hidden.
              You can close it:
              @dialog->close();@
              You can delete it:
              @delete dialog;
              dialog = 0;@
              You can show it:
              @dialog->exec()@

              sorry for my english :(

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulienMaille
                wrote on last edited by
                #8

                In fact my dialog checks for software updates: it shows the software version, then opens a distant xml file and displays a download button if a newer version exists.
                This works perfectly, but now I would like to add an option to silently check for update and show the dialog only if a newer version exists.

                [quote author="Volker" date="1306836130"]Where is the code that "controls" the display behavior?[/quote] Partly in the constructor and partly in the slots connected to a QNetworkReply object.

                Right now everything is done in the constructor. I like it because from my main I can call exec wihch is blocking, and everything is done in the subclass

                If I don't call exec, my UpdatesDialog will be immediatly destroyed. To avoid this, I need a pointer to it, then to connect it to slot of my mainwindow, etc.. @void MainWindow::slotCheckForUpdatesClicked()
                {
                UpdatesDialog dialog(GLOBAL_MAJOR, GLOBAL_MINOR, GLOBAL_BUILD, GLOBAL_ARCH64, true, this);
                dialog.exec();
                } @

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #9

                  Then move the check out of the dialog into your main application or something else and open the dialog only if there is an update.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulienMaille
                    wrote on last edited by
                    #10

                    I solved it by optionally calling exec from the constructor.
                    Thanks everybody!

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #11

                      This makes your constructor to not finish (read your constructor returns only after your dialog has been executed) before your dialog is dismissed.

                      If you ever happen to subclass your dialog, you will work on an not completely constructed object and you're most likely to crash your app!

                      DO NOT DO THIS!

                      You have been showed a way to do it properly.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JulienMaille
                        wrote on last edited by
                        #12

                        Oops, ok I'll change this right now!

                        1 Reply Last reply
                        0

                        • Login

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