Pasting from main menu
-
wrote on 19 Jan 2022, 15:28 last edited by
I have an application that has a main window containing three windows (typical layout one central widget and two docked, one left and one bottom).
I now want to manage enable and disable of Paste command in the main Edit menu. One important aspect of this is what window has focus. I can paste in central and left widget but not on bottom widget. So, depending on who has focus the Paste action needs to be enabled or disabled. Also the actual implementation of enable/disable logic needs to shift as each view will decide, dependent on clipboard contents, whether it may paste what is there or not. I fail to find out how I can do this. I tried using QFocusEvents but as I select the main menu the 'current' view lose focus and thus disables the paste command.
I also need to update the state of the command if I click around in the application as there is a toolbar button for the action.
It seems like a simple problem but I got stuck and all I can think of is to manage this in every window which feels like a fragile and not so elegant solution. I'd rather not have all windows dealing with commands they have no interest in. -
I have an application that has a main window containing three windows (typical layout one central widget and two docked, one left and one bottom).
I now want to manage enable and disable of Paste command in the main Edit menu. One important aspect of this is what window has focus. I can paste in central and left widget but not on bottom widget. So, depending on who has focus the Paste action needs to be enabled or disabled. Also the actual implementation of enable/disable logic needs to shift as each view will decide, dependent on clipboard contents, whether it may paste what is there or not. I fail to find out how I can do this. I tried using QFocusEvents but as I select the main menu the 'current' view lose focus and thus disables the paste command.
I also need to update the state of the command if I click around in the application as there is a toolbar button for the action.
It seems like a simple problem but I got stuck and all I can think of is to manage this in every window which feels like a fragile and not so elegant solution. I'd rather not have all windows dealing with commands they have no interest in.wrote on 19 Jan 2022, 16:21 last edited by -
wrote on 20 Jan 2022, 13:32 last edited by
I found a solution after some sleep. I needed to catch the QApplication::focusChanged signal and then basically do my own handling from there. When I tried this the first time I did not realize I needed to walk up the widget chain to find a parent which was a 'IPasteHandler' (my invented interface implemented by windows handling the paste command).
1/3