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. Can't detect if widget/ui is visible
Qt 6.11 is out! See what's new in the release blog

Can't detect if widget/ui is visible

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 5 Posters 7.3k Views 3 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.
  • L Offline
    L Offline
    LovelyGrace
    wrote on last edited by
    #1

    I've been trying to debug using qDebug() << dialog.isVisible() << endl; to determine if dialog show up whenever I click the button, but it always set to false even if it really is visible. How do I determine if the dialog is visible?

    RatzzR 1 Reply Last reply
    0
    • L LovelyGrace

      I've been trying to debug using qDebug() << dialog.isVisible() << endl; to determine if dialog show up whenever I click the button, but it always set to false even if it really is visible. How do I determine if the dialog is visible?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @LovelyGrace

      Can you show your code?

      --Alles ist gut.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LovelyGrace
        wrote on last edited by
        #3

        from mainwindow.cpp

        void MainWindow::on_pushButton_clicked()
        {
        Dialog dialog(this);
        dialog.setModal(true);
        dialog.exec();
        dialog.move(this->rect().center() - dialog.rect().center());
        //dialog.setAttribute(Qt::WA_ShowWithoutActivating, true);
        //dialog.setWindowFlags(/*Qt::Tool | / Qt::X11BypassWindowManagerHint /| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint */);

        qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl;
        

        }

        jsulmJ RatzzR 2 Replies Last reply
        0
        • L LovelyGrace

          from mainwindow.cpp

          void MainWindow::on_pushButton_clicked()
          {
          Dialog dialog(this);
          dialog.setModal(true);
          dialog.exec();
          dialog.move(this->rect().center() - dialog.rect().center());
          //dialog.setAttribute(Qt::WA_ShowWithoutActivating, true);
          //dialog.setWindowFlags(/*Qt::Tool | / Qt::X11BypassWindowManagerHint /| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint */);

          qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl;
          

          }

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LovelyGrace You're showing your dialog as modal (exec(), dialog.setModal(true); is not needed if you use exec()). That means when exec() finishes your dialog is not shown anymore!
          You can try this

          
          from mainwindow.cpp
          
          void MainWindow::on_pushButton_clicked()
          {
              Dialog *dialog = new Dialog(this);
              dialog.show();
              dialog.move(this->rect().center() - dialog.rect().center());
          
              qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl;
          }
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • L LovelyGrace

            from mainwindow.cpp

            void MainWindow::on_pushButton_clicked()
            {
            Dialog dialog(this);
            dialog.setModal(true);
            dialog.exec();
            dialog.move(this->rect().center() - dialog.rect().center());
            //dialog.setAttribute(Qt::WA_ShowWithoutActivating, true);
            //dialog.setWindowFlags(/*Qt::Tool | / Qt::X11BypassWindowManagerHint /| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint */);

            qDebug() << "Is Dialog visible from pushbutton: " << dialog.isVisible() << endl;
            

            }

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by Ratzz
            #5

            @LovelyGrace said in Can't detect if widget/ui is visible:

            dialog.exec();

            As @jsulm suggested you need to use show() because dialog will be in blocked state until user closes the dialog. You are checking isVisible() after you closed the dialog. So dialog.isVisible() returns false.

            --Alles ist gut.

            1 Reply Last reply
            1
            • L Offline
              L Offline
              LovelyGrace
              wrote on last edited by LovelyGrace
              #6

              how am I going to do this from another class but not in the mainwindow?? I tried this with calling the dialog class using Dialog *dialog; from the newDialog class private section: But it didn;t work, tried putting 'this' but error exist

              void newDialog::startDialog()
              {
              Dialog dialog;
              dialog.setModal(true);

              if(dialog.isVisible())
              {
                  qDebug() << "Dialog is Visible to newDialog Class" << endl;
              }
              

              }

              RatzzR 1 Reply Last reply
              0
              • L LovelyGrace

                how am I going to do this from another class but not in the mainwindow?? I tried this with calling the dialog class using Dialog *dialog; from the newDialog class private section: But it didn;t work, tried putting 'this' but error exist

                void newDialog::startDialog()
                {
                Dialog dialog;
                dialog.setModal(true);

                if(dialog.isVisible())
                {
                    qDebug() << "Dialog is Visible to newDialog Class" << endl;
                }
                

                }

                RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on last edited by
                #7

                @LovelyGrace said in Can't detect if widget/ui is visible:

                But it didn;t work

                Can you show the code?

                error exist

                What is the error?

                --Alles ist gut.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  LovelyGrace
                  wrote on last edited by LovelyGrace
                  #8

                  from the code above, no error exist, but it it didn't detect if the dialog is visible from the newDialog class

                  RatzzR 1 Reply Last reply
                  0
                  • L LovelyGrace

                    from the code above, no error exist, but it it didn't detect if the dialog is visible from the newDialog class

                    RatzzR Offline
                    RatzzR Offline
                    Ratzz
                    wrote on last edited by
                    #9

                    @LovelyGrace said in Can't detect if widget/ui is visible:

                    but it it didn't detect if the dialog is visible from the newDialog class

                    How are you doing it.

                    --Alles ist gut.

                    L 1 Reply Last reply
                    1
                    • RatzzR Ratzz

                      @LovelyGrace said in Can't detect if widget/ui is visible:

                      but it it didn't detect if the dialog is visible from the newDialog class

                      How are you doing it.

                      L Offline
                      L Offline
                      LovelyGrace
                      wrote on last edited by
                      #10

                      if you mean using this:
                      Dialog *dialog = new Dialog(this);

                      the error says when I tried calling Dialog from newDialog class
                      error: no matching function for call

                      RatzzR 1 Reply Last reply
                      0
                      • L LovelyGrace

                        if you mean using this:
                        Dialog *dialog = new Dialog(this);

                        the error says when I tried calling Dialog from newDialog class
                        error: no matching function for call

                        RatzzR Offline
                        RatzzR Offline
                        Ratzz
                        wrote on last edited by
                        #11

                        @LovelyGrace said in Can't detect if widget/ui is visible:

                        error: no matching function for call

                        Can you show your Dialog class?

                        --Alles ist gut.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          LovelyGrace
                          wrote on last edited by
                          #12

                          @Ratzz mainwindow detect dialog class but newDialog can't

                          I tried calling Dialog class from the newDialog class and create a function from the newDialog class to test if it can detect the dialog when it runs, but it didn't. Using this code:

                          void newDialog::startDialog()
                          {
                          if(dialog.isVisible())
                          {
                          qDebug() << "Dialog is Visible to newDialog Class" << endl;
                          }

                          RatzzR 1 Reply Last reply
                          0
                          • L LovelyGrace

                            @Ratzz mainwindow detect dialog class but newDialog can't

                            I tried calling Dialog class from the newDialog class and create a function from the newDialog class to test if it can detect the dialog when it runs, but it didn't. Using this code:

                            void newDialog::startDialog()
                            {
                            if(dialog.isVisible())
                            {
                            qDebug() << "Dialog is Visible to newDialog Class" << endl;
                            }

                            RatzzR Offline
                            RatzzR Offline
                            Ratzz
                            wrote on last edited by
                            #13

                            @LovelyGrace said in Can't detect if widget/ui is visible:

                            if(dialog.isVisible())

                            Where do you use show()

                            --Alles ist gut.

                            1 Reply Last reply
                            3
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Hi,

                              @LovelyGrace said in Can't detect if widget/ui is visible:

                              void newDialog::startDialog()
                              {
                              Dialog dialog;
                              dialog.setModal(true);
                              if(dialog.isVisible())
                              {
                              qDebug() << "Dialog is Visible to newDialog Class" << endl;
                              }

                              }

                              You haven't called show yet.

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

                              L 1 Reply Last reply
                              1
                              • SGaistS SGaist

                                Hi,

                                @LovelyGrace said in Can't detect if widget/ui is visible:

                                void newDialog::startDialog()
                                {
                                Dialog dialog;
                                dialog.setModal(true);
                                if(dialog.isVisible())
                                {
                                qDebug() << "Dialog is Visible to newDialog Class" << endl;
                                }

                                }

                                You haven't called show yet.

                                L Offline
                                L Offline
                                LovelyGrace
                                wrote on last edited by
                                #15

                                @SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running

                                jsulmJ SGaistS 2 Replies Last reply
                                0
                                • L LovelyGrace

                                  @SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @LovelyGrace Did you make sure that show() was called?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • L LovelyGrace

                                    @SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running

                                    SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @LovelyGrace said in Can't detect if widget/ui is visible:

                                    @SGaist Hi show() function is in the mainwindow class, new Dialog class is supposed to check whether the dialog is running

                                    I meant dialog.show().

                                    The code you wrote will just create a dialog, and then destroy it since it's local to that method.

                                    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
                                    • L Offline
                                      L Offline
                                      LovelyGrace
                                      wrote on last edited by
                                      #18

                                      show() is running on the main window, what I want to happen is that newDialog will only detect if Dialog is running from the mainwindow and it's not supposed to show from the newDialog.

                                      mrjjM 1 Reply Last reply
                                      0
                                      • L LovelyGrace

                                        show() is running on the main window, what I want to happen is that newDialog will only detect if Dialog is running from the mainwindow and it's not supposed to show from the newDialog.

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by mrjj
                                        #19

                                        @LovelyGrace
                                        If mainwindows knows if "Dialog" (bad class name) is shown or not and also shows newDialog when asked, why not let main window handle the logic ?

                                        Its seems odd that newDialog will show an other dialog if its not already on screen since its not the the one that put it there. Also if you open new dialog in newDialog, main window will not have access to that instance ( copy) and
                                        cant tell if its open or not.

                                        1 Reply Last reply
                                        1
                                        • L Offline
                                          L Offline
                                          LovelyGrace
                                          wrote on last edited by
                                          #20

                                          how can i connect then the Dialog class to new Dialog class?

                                          mrjjM 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