QDialog: show() vs open() - qt

Whats the difference between QDialog::show() and QDialog::open()?

show() will just show you the dialog without affecting the other windows in your program. open() will show() the window + prevent other windows from being accessible through setWindowModality(), i.e., it becomes a modal window.
This is useful if you want to open a file, for example, and you don't want the user to be able to do anything in the program until a file is chosen and that dialog is closed.
Quoting from Qt's manual:
A modal dialog is a dialog that blocks input to other visible windows in the same application. Dialogs that are used to request a file name from the user or that are used to set application preferences are usually modal. Dialogs can be application modal (the default) or window modal.
When an application modal dialog is opened, the user must finish interacting with the dialog and close it before they can access any other window in the application. Window modal dialogs only block access to the window associated with the dialog, allowing the user to continue to use other windows in an application.
The most common way to display a modal dialog is to call its exec() function. When the user closes the dialog, exec() will provide a useful return value. Typically, to get the dialog to close and return the appropriate value, we connect a default button, e.g. OK, to the accept() slot and a Cancel button to the reject() slot. Alternatively you can call the done() slot with Accepted or Rejected.

As it is stated in the doc, QDialog::open()
Shows the dialog as a window modal dialog, returning immediately.
whereas QDialog::show(), which is in fact QWidget::show(), will only show your dialog as a standard, non-modal widget.

Related

Prevent QMainWindow from jumping to foreground after closing QDialog

I'm developing a Qt-based app, using QMainWindow class for the GUI. This app has a built-in server that listens for requests from my Chrome Browser extension, so that I may import information from current web-page into my Qt-app.
So when I press extension's button in the browser, it sends a signal to my Qt-app, which then pops up a QDialog so that I can add some additional information like tags, etc. When I close the QDialog, I expect to return to the browser, but instead my app's main window pops up into foreground if it wasn't minimized (if it was minimized, then it doesn't pop up).
How can I change this behavior, so that I return to my browser after closing QDialog, no matter if the app's main window was minimized or not? If that helps, when creating QDialog, I pass 0 as parent to it.

How do you make a modal QDialog impossible to close via user input

I have a QDialog which i'd like to be modal, i.e. I'd like the user to be locked out of the GUI completely until I programatically hide the dialog.
Here is a small reproducible example:
QDialog *dialog = new QDialog(this, Qt::Splashscreen);
dialog->setModal(true);
dialog->setWindowModality(Qt::ApplicationModal);
dialog->exec();
This is easily closed by clicking outside of the dialog.
Pressing the esc key would also close the dialog however in my custom implementation I am catching the event and dealing with it separately.
Edits
This only seems to occur on Windows, on Linux it behaves as desired.
Pressing alt + F4also closes the dialog regardless of catching key events.

Unable to switch to Alert without closing window popup in webdriver

Scenario:
Enter a keyword (Position) in a textbox
press Tab or click on the next element
A window popup appears
a list of position matching the criteria will be listed
click the required record
Popup window closes automatically
Alert will be displayed
have click on ok button of alert.
switch to main window and check the position details
Question :- i found many solutions in the site but all are about performing actions on window popup and close the popup then switch to alert or main browser
but my application closes the popup window automatically after selection,hence i cannot use the driver.close() or driver.switchto.defaultContent().
If i dont close the driver (for popup) im not able to identify the next alert displayed after popup.
if i switch directly to mainwindhandle, the alert dismiss is happening instead of accept.
Please anyone who know how to switch from window popup to alert without popup close help is needed...
Thanks ....
If alert dismiss is happening when you are trying to accept it, why don't you use alert.dismiss(), it will probably accept the alert in your context.
When you switch to the popup window, the driver focus is on the popup window. What you might want to do is, just after clicking the required record, switch to the main window then accept the alert.
This must be helpful for you . From your questions, Even after your pop up closes automatically you must be able to access your parent window element by switching back to it. There is no need of driver.close() all the time. Here is the code,
// do something with the pop up and it closes automatically here.
driver.switchTo().defaultContent();
driver.switchTo().frame("your parent window mainframe"));
// try to access your parent window element here

Get active modal QWidget

I need to know in my app if a modal window is opened when I click on a button.
So I'm searching for a method which permits to know if a modal window is opened in my application or no, and which returns the window (or NULL)
Is it possible?
See QApplication's static activeModalWidget

Close all popup dialogs when main window closed in ASP.NET

In my web application a lot of popups opened from the parent window using 'window.open'. So I want to close all those popups when my application's main window is closed. How can I do that?
It's a bit problematic to know that the user closes the window but assuming you do achieve that (by a close button or subscribing to the beforeUnload event) you can close the opened windows by following the next bullets:
When opening a window, save its
object which is returned from the
window.open method (preferably to an
array so you have all objects in a
central place).
When you find out the main window is
closing, execute the close method
on the saved window objects.
Another possibility:
Use timer on the opened windows to
check if opener is defined (you
can try to use typeof on a method in
the opener page).
When you find out the opener doesn't
exist, close the window.
There's no callback that will notify you that the user closed his browser.
its not possible! You cannot catch browser close event.
You can use model popups to be sure user closed popups before closing the main window.

Resources