Bring QFileDialog to the front
-
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
-
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
} -
@JoeCFD
What isthis
, which you pass as the parent toQFileDialog( this)
?
I'm not sure how that combines withsetWindowModality( Qt::ApplicationModal )
anyway....
I have not had to usesetWindowModality( Qt::ApplicationModal )
norsetWindowFlags( 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. -
@JoeCFD
Then I think that is your problem, because IIRCQFileDialog
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?
-
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
-
@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;
}
}