Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Pasting from main menu
QtWS25 Last Chance

Pasting from main menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 324 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PeterB
    wrote on 19 Jan 2022, 15:28 last edited by
    #1

    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.

    P 1 Reply Last reply 19 Jan 2022, 16:21
    0
    • P PeterB
      19 Jan 2022, 15:28

      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.

      P Offline
      P Offline
      Pl45m4
      wrote on 19 Jan 2022, 16:21 last edited by
      #2

      @PeterB

      Seems like a case for:

      https://doc.qt.io/qt-5/qt.html#ShortcutContext-enum


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • P Offline
        P Offline
        PeterB
        wrote on 20 Jan 2022, 13:32 last edited by
        #3

        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 Reply Last reply
        0

        1/3

        19 Jan 2022, 15:28

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved