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. Loop images within one QDialog, closing all Windows and open new Window with button
Forum Updated to NodeBB v4.3 + New Features

Loop images within one QDialog, closing all Windows and open new Window with button

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 366 Views 2 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on last edited by Chris Kawa
    #1

    I need to loop images within one QDialog, closing all Windows and open new Window with button

    using chunk below:

    #include "DialogManager.h"
    
    QList<QDialog*> DialogManager::dialogs;
    
    void DialogManager::addDialog(QDialog *dialog) {
        if (dialog) {
            dialogs.append(dialog);
        }
    }
    
    void DialogManager::closeAllDialogs() {
        for (QDialog *dialog : dialogs) {
            if (dialog) {
                dialog->close();
            }
        }
     
        dialogs.clear();
    }
    
     qDebug() << "Closing all dialogs";
    
    
        qDebug() << "Attempting to close current dialog";
        this->close();
    
    
        QTimer::singleShot(0, this, [this]() {
            qDebug() << "Current dialog closed, creating new Frames dialog";
    
            
            ClassName *a = new ClassName();
            a->functionName(l_path, qnumber, "", "");
            a->setWindowFlag(Qt::WindowStaysOnTopHint);
            a->setGeometry(0, 0, 1850, 850); // Adjust the geometry as needed
            a->setWindowTitle("Frame#" + qnumber);
            a->setAttribute(Qt::WA_DeleteOnClose);
            a->show();
    
        });
         DialogManager::closeAllDialogs();
    

    but I can only use this function this way
    I open QDialog, push button to open next image, it closes current dialog
    returns to mainWindow where I repeat this cycle
    its not really convenient, so I'm asking for your kind support

    Pl45m4P 1 Reply Last reply
    0
    • J JacobNovitsky

      I need to loop images within one QDialog, closing all Windows and open new Window with button

      using chunk below:

      #include "DialogManager.h"
      
      QList<QDialog*> DialogManager::dialogs;
      
      void DialogManager::addDialog(QDialog *dialog) {
          if (dialog) {
              dialogs.append(dialog);
          }
      }
      
      void DialogManager::closeAllDialogs() {
          for (QDialog *dialog : dialogs) {
              if (dialog) {
                  dialog->close();
              }
          }
       
          dialogs.clear();
      }
      
       qDebug() << "Closing all dialogs";
      
      
          qDebug() << "Attempting to close current dialog";
          this->close();
      
      
          QTimer::singleShot(0, this, [this]() {
              qDebug() << "Current dialog closed, creating new Frames dialog";
      
              
              ClassName *a = new ClassName();
              a->functionName(l_path, qnumber, "", "");
              a->setWindowFlag(Qt::WindowStaysOnTopHint);
              a->setGeometry(0, 0, 1850, 850); // Adjust the geometry as needed
              a->setWindowTitle("Frame#" + qnumber);
              a->setAttribute(Qt::WA_DeleteOnClose);
              a->show();
      
          });
           DialogManager::closeAllDialogs();
      

      but I can only use this function this way
      I open QDialog, push button to open next image, it closes current dialog
      returns to mainWindow where I repeat this cycle
      its not really convenient, so I'm asking for your kind support

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @JacobNovitsky said in Loop images within one QDialog, closing all Windows and open new Window with button:

      I need to loop images within one QDialog

      The posted code doesn't show anything related to "loop images"?!
      And I find it quite confusing what you do with your dialogs.

      Can you tell what you are actually looking for? What should the Dialog do?

      Where do your images come from? How do you store them? Do you want to show them one after another? Like a slide show?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      J 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @JacobNovitsky said in Loop images within one QDialog, closing all Windows and open new Window with button:

        I need to loop images within one QDialog

        The posted code doesn't show anything related to "loop images"?!
        And I find it quite confusing what you do with your dialogs.

        Can you tell what you are actually looking for? What should the Dialog do?

        Where do your images come from? How do you store them? Do you want to show them one after another? Like a slide show?

        J Offline
        J Offline
        JacobNovitsky
        wrote on last edited by
        #3

        @Pl45m4
        images stored at ~/Pictures
        I need to loop each image and see its output on button click on same Dialog
        each button click must close previous Dialog and Open new (refresh, to prevent memory leak)

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

          Hi,

          Why not change the content of the label rather than recreating the exact same dialog all the time ?

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

          J 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            Why not change the content of the label rather than recreating the exact same dialog all the time ?

            J Offline
            J Offline
            JacobNovitsky
            wrote on last edited by
            #5

            @SGaist do you mean pushbutton -> set new label?

            JonBJ 1 Reply Last reply
            0
            • J JacobNovitsky

              @SGaist do you mean pushbutton -> set new label?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @JacobNovitsky Just call QLabel::setPixmap(const QPixmap &) to the next pixmap.

              1 Reply Last reply
              2
              • J JacobNovitsky

                @Pl45m4
                images stored at ~/Pictures
                I need to loop each image and see its output on button click on same Dialog
                each button click must close previous Dialog and Open new (refresh, to prevent memory leak)

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @JacobNovitsky said in Loop images within one QDialog, closing all Windows and open new Window with button:

                images stored at ~/Pictures
                I need to loop each image and see its output on button click on same Dialog
                each button click must close previous Dialog and Open new (refresh, to prevent memory leak)

                No.
                How about reading all files name and store them in some QFileInfoList and then navigate through the list showing one image at a time in the same dialog. You don't have to re-create the dialog to show another image.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                J 1 Reply Last reply
                1
                • Pl45m4P Pl45m4

                  @JacobNovitsky said in Loop images within one QDialog, closing all Windows and open new Window with button:

                  images stored at ~/Pictures
                  I need to loop each image and see its output on button click on same Dialog
                  each button click must close previous Dialog and Open new (refresh, to prevent memory leak)

                  No.
                  How about reading all files name and store them in some QFileInfoList and then navigate through the list showing one image at a time in the same dialog. You don't have to re-create the dialog to show another image.

                  J Offline
                  J Offline
                  JacobNovitsky
                  wrote on last edited by
                  #8

                  @Pl45m4 thanks! I was pretty dumb to not consider this natural variant

                  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