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.5k 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 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
                  • L LovelyGrace

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

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

                    @LovelyGrace
                    well that you can also do from main window since it has both
                    pointers to the DialogClass and newDialogClass

                    connect( DialogClassPTR, SOMESIGNAL,newDialogClassPTR, SOMESLOT);

                    and also the other way if u need newDialog to talk to Dialog

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

                      What is your exact purpose with finding the visibility of that dialog ?

                      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
                        #23

                        I will be making a function that only works if the dialog from the other class is visible or active.

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

                          mainwindow can now communicate with the newDialog, but why can't newDialog detect if Dialog is visible?

                          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 */);

                          dialog = new Dialog();
                          dialog->show();
                          dialog->move(this->rect().center() - dialog->rect().center());
                          
                          qDebug() << "Is Dialog visible from pushbutton: " << dialog->isVisible() << endl;
                          
                          nDialog = new newDialog();
                          nDialog->startDialog();
                          

                          }

                          void newDialog::startDialog()
                          {
                          qDebug() << "DIALOG TO NEWDIALOG" << endl;
                          dialog = new Dialog();

                          if(dialog->isVisible())
                          {
                              qDebug() << "Dialog is Visible to newDialog Class" << endl;
                          }
                          
                          if(dialog->isActiveWindow())
                          {
                              qDebug() << "Dialog is Active to newDialog Class" << endl;
                          }
                          

                          }

                          The output is:
                          Is Dialog visible from pushbutton: true -- from mainwindow

                          DIALOG TO NEWDIALOG -- from newDialog

                          mrjjM 1 Reply Last reply
                          0
                          • L LovelyGrace

                            mainwindow can now communicate with the newDialog, but why can't newDialog detect if Dialog is visible?

                            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 */);

                            dialog = new Dialog();
                            dialog->show();
                            dialog->move(this->rect().center() - dialog->rect().center());
                            
                            qDebug() << "Is Dialog visible from pushbutton: " << dialog->isVisible() << endl;
                            
                            nDialog = new newDialog();
                            nDialog->startDialog();
                            

                            }

                            void newDialog::startDialog()
                            {
                            qDebug() << "DIALOG TO NEWDIALOG" << endl;
                            dialog = new Dialog();

                            if(dialog->isVisible())
                            {
                                qDebug() << "Dialog is Visible to newDialog Class" << endl;
                            }
                            
                            if(dialog->isActiveWindow())
                            {
                                qDebug() << "Dialog is Active to newDialog Class" << endl;
                            }
                            

                            }

                            The output is:
                            Is Dialog visible from pushbutton: true -- from mainwindow

                            DIALOG TO NEWDIALOG -- from newDialog

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

                            @LovelyGrace
                            Hi is a brain bug. ;)

                            You open and show "Dialog" in mainwindow.

                            Then in NewDialog
                            you create a yet other new "Dialog",
                            that you DO NOT show and then ask it if its visible. ( which its not)

                            it will know NOTHING about the first dialog in main. the isVisible is pr copy u make.

                            if you really just mean to create the other new dialog in NewDialog then

                            void newDialog::startDialog()
                            {
                            qDebug() << "DIALOG TO NEWDIALOG" << endl;
                            dialog = new Dialog();
                            dialog ->show(); ///////////////////////////// else it 100% wont be visible
                            
                            • from main.
                              if you really want to do it this way
                              then
                              nDialog = new newDialog();
                              nDialog->startDialog(dialog); // give it the pointer to new dialog.
                              or
                              simeply tell it
                              nDialog->startDialog( dialog->isVisible() );// give a bool

                            so to repeat
                            You CANNOT create yet another copy of dialog to ask if the first copy u made in mainwindow is visible.

                            1 Reply Last reply
                            3

                            • Login

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