I set windowModality to 2, which is ApplicationModal. However, you can still click on the parent window, which causes the child window to flash. This would be acceptable, although it doesn't look great.
However, sometimes I need to create a dialog from another dialog. When doing this, you can click on the main window, causing the parent of the second dialog to disappear behind the window and not reappear until the second dialog is closed. I worry this would be confusing to the user.
Does anyone know how I can make this behave like Windows and macOS? All PB Windows, including those from the Dialog library, are based on QMainWindow. I have a feeling that to get this behaviour, they would have to be based on QDialog, but I hope not.
Code: Select all
Enumeration
#Window
#Button
#Dialog
#DialogButton
#Dialog2
EndEnumeration
OpenWindow(#Window, 0, 0, 400, 350, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Button, 10, 10, 90, 25, "Open Dialog")
Define Event
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window
Quit = 1
Case #Dialog
CloseWindow(#Dialog)
DisableWindow(#Window, 0)
Case #Dialog2
CloseWindow(#Dialog2)
DisableWindow(#Dialog, 0)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Button
OpenWindow(#Dialog, 0, 0, 320, 240, "Dialog", #PB_Window_SystemMenu | #PB_Window_WindowCentered, WindowID(#Window))
QtScript("window(" + #Dialog + ").windowModality = 2")
QtScript("window(" + #Dialog + ").hide();" + "window(" + #Dialog + ").show()")
ButtonGadget(#DialogButton, 10, 10, 90, 25, "Open Dialog")
Case #DialogButton
OpenWindow(#Dialog2, 0, 0, 300, 200, "Dialog 2", #PB_Window_SystemMenu | #PB_Window_WindowCentered, WindowID(#Dialog))
QtScript("window(" + #Dialog2 + ").windowModality = 2")
QtScript("window(" + #Dialog2 + ").hide();" + "window(" + #Dialog2 + ").show()")
EndSelect
EndSelect
Until Quit = 1
End