It is currently Mon Sep 23, 2019 4:54 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Qt - Modal dialogs?
PostPosted: Thu Mar 21, 2019 4:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 451
I am trying to create modal style dialog windows, but I'm encountering some problems. I can't use DisableWindow() because that disables child windows.

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:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye