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. Bring QFileDialog to the front

Bring QFileDialog to the front

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 2.1k 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by
    #1

    I use exec() call to pop a qfiledialog up and found it is minimized while it is used in a DLL and its parent is not the mainwindow. Googled it and tried all I could find: modality, flags, raise, etc and could not solve this problem. Need help. Thanks in advance

    RatzzR 1 Reply Last reply
    0
    • JoeCFDJ JoeCFD

      I use exec() call to pop a qfiledialog up and found it is minimized while it is used in a DLL and its parent is not the mainwindow. Googled it and tried all I could find: modality, flags, raise, etc and could not solve this problem. Need help. Thanks in advance

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

      @JoeCFD
      Can you show me your code?

      --Alles ist gut.

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        QFileDialog * dialog = new QFilieDialog( this);
        dialog->setWindowTitle( "App" );
        dialog->setWindowModality( Qt::ApplicationModal );
        dialog->setWindowFlags( Qt::WindowStaysOnTop );
        dialog->setAcceptMode(QFileDialog::AcceptSave );
        ....
        if ( QDialog::Accepted == dialog->exec() )
        {
        do something
        }

        JonBJ 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          QFileDialog * dialog = new QFilieDialog( this);
          dialog->setWindowTitle( "App" );
          dialog->setWindowModality( Qt::ApplicationModal );
          dialog->setWindowFlags( Qt::WindowStaysOnTop );
          dialog->setAcceptMode(QFileDialog::AcceptSave );
          ....
          if ( QDialog::Accepted == dialog->exec() )
          {
          do something
          }

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

          @JoeCFD
          What is this, which you pass as the parent to QFileDialog( this)?
          I'm not sure how that combines with setWindowModality( Qt::ApplicationModal ) anyway....
          I have not had to use setWindowModality( Qt::ApplicationModal ) nor setWindowFlags( Qt::WindowStaysOnTop );, but I admit I haven't done Windows/DLLs.

          I think from what you write that if you ensure you pass the main window as the parent to new QFileDialog( this) you will get you want.

          JoeCFDJ 1 Reply Last reply
          1
          • JonBJ JonB

            @JoeCFD
            What is this, which you pass as the parent to QFileDialog( this)?
            I'm not sure how that combines with setWindowModality( Qt::ApplicationModal ) anyway....
            I have not had to use setWindowModality( Qt::ApplicationModal ) nor setWindowFlags( Qt::WindowStaysOnTop );, but I admit I haven't done Windows/DLLs.

            I think from what you write that if you ensure you pass the main window as the parent to new QFileDialog( this) you will get you want.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @JonB Right.Here "this" is another widget, not the mainwindow. If I pass my mainwindow as this, it is all right. However, I can not use it since this piece of code is in a DLL. The mainwindow is not available.

            JonBJ 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @JonB Right.Here "this" is another widget, not the mainwindow. If I pass my mainwindow as this, it is all right. However, I can not use it since this piece of code is in a DLL. The mainwindow is not available.

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

              @JoeCFD
              Then I think that is your problem, because IIRC QFileDialog likes the main window not a widget as its parent if it's to behave modally the way you want.

              If that is true, the DLL is running in your program's user space, so when you say "The mainwindow is not available" you can always go get it. That's what I've done in my code (though nothing to do with DLLs/Windows). You might at least try that to see if it solves your problem?

              JoeCFDJ 1 Reply Last reply
              0
              • JonBJ JonB

                @JoeCFD
                Then I think that is your problem, because IIRC QFileDialog likes the main window not a widget as its parent if it's to behave modally the way you want.

                If that is true, the DLL is running in your program's user space, so when you say "The mainwindow is not available" you can always go get it. That's what I've done in my code (though nothing to do with DLLs/Windows). You might at least try that to see if it solves your problem?

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #7

                @JonB I can send a signal to the mainwindow to do the popup over there and solve the problem. But it is not convienent. Thanks anyway.

                JoeCFDJ JonBJ 2 Replies Last reply
                0
                • JoeCFDJ JoeCFD

                  @JonB I can send a signal to the mainwindow to do the popup over there and solve the problem. But it is not convienent. Thanks anyway.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #8

                  @JoeCFD It turns out it is a virtual machine issue. On Linux within a virtual machine this problem shows up. Not sure why. No problem on a standalone Linux.

                  1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @JonB I can send a signal to the mainwindow to do the popup over there and solve the problem. But it is not convienent. Thanks anyway.

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

                    @JoeCFD

                    I can send a signal to the mainwindow to do the popup over there and solve the problem. But it is not convienent. Thanks anyway.

                    You could, but that wasn't what I intended, I understand that would mean re-architecting. I meant: discover it where you open the file dialog, in your DLL, without having to pass it around in code. If you're interested, I wrote:

                    def findMainWindow() -> typing.Union[QMainWindow, None]:
                        # Global function to find the (open) QMainWindow in application
                        app = QApplication.instance()
                        for widget in app.topLevelWidgets():
                            if isinstance(widget, QMainWindow):
                                return widget
                        return None
                    
                    JoeCFDJ 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @JoeCFD

                      I can send a signal to the mainwindow to do the popup over there and solve the problem. But it is not convienent. Thanks anyway.

                      You could, but that wasn't what I intended, I understand that would mean re-architecting. I meant: discover it where you open the file dialog, in your DLL, without having to pass it around in code. If you're interested, I wrote:

                      def findMainWindow() -> typing.Union[QMainWindow, None]:
                          # Global function to find the (open) QMainWindow in application
                          app = QApplication.instance()
                          for widget in app.topLevelWidgets():
                              if isinstance(widget, QMainWindow):
                                  return widget
                          return None
                      
                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @JonB Got it.This is something new for me. Thanks a lot.

                      something like the following works.

                      QWidget * widget{ nullptr };
                      for ( widget : QApplication::toLevelWidgets() )
                      {
                      if ( widget->objectName() == QString( "MyMainWindow" ) )
                      {
                      break;
                      }
                      }

                      JonBJ 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @JonB Got it.This is something new for me. Thanks a lot.

                        something like the following works.

                        QWidget * widget{ nullptr };
                        for ( widget : QApplication::toLevelWidgets() )
                        {
                        if ( widget->objectName() == QString( "MyMainWindow" ) )
                        {
                        break;
                        }
                        }

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

                        @JoeCFD
                        If this helps you I am glad.

                        If you wanted to write the direct equivalent of Python's if isinstance(widget, QMainWindow) in C++ you should be able to use if (dynamic_cast<QMainWindow*>(widget)).

                        JoeCFDJ 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @JoeCFD
                          If this helps you I am glad.

                          If you wanted to write the direct equivalent of Python's if isinstance(widget, QMainWindow) in C++ you should be able to use if (dynamic_cast<QMainWindow*>(widget)).

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by JoeCFD
                          #12

                          @JonB My C++ code is good enough to solve the issue. No casting is needed. Many thanks again.

                          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