Results 1 to 4 of 4

Thread: copy/paste actions in main window menu

  1. #1
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question copy/paste actions in main window menu

    I have a cut/copy/paste menu in my QMainWindow, and I've set the standard shortcuts. I have a number of child windows of different types.

    When, for example, Ctrl+C is pressed in one of the child windows, I would like the keyPressEvent to be called first in that child window. But that's not what happens... instead the main window takes over.

    My workaround so far has been for the main window to figure out who has the focus and then pass the event back down - but I don't want to do that any more.

    What's the right way to handle this? Any suggestions?
    Last edited by magland; 2nd October 2007 at 11:52. Reason: set question icon

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: copy/paste actions in main window menu

    Try reimplementing event() for the child (or apply an event filter) and process the key yourself there. You can also change the context of the shortcut to Qt::WidgetShortcut, maybe this will be enough.

  3. The following user says thank you to wysota for this useful post:

    magland (2nd October 2007)

  4. #3
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: copy/paste actions in main window menu

    Quote Originally Posted by wysota View Post
    Try reimplementing event() for the child (or apply an event filter) and process the key yourself there. You can also change the context of the shortcut to Qt::WidgetShortcut, maybe this will be enough.
    That's a good hint, Wysota. I'm now using setShortcutContext(Qt::WidgetShortcut), and in effect it completely disables the shortcuts -- but that's a good thing. The advantage of this, as opposed to removing the shortcuts completely, is that the "Ctrl+C" text still appears in the menu.

    My last step is to catch the QKeyEvent in the main window and send them down to the children when appropriate. Could you please tell me: does a keyPressEvent bubble up/bubble down?

    Thanks

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: copy/paste actions in main window menu

    All events propagate from children to parents until they are handled.

  6. The following user says thank you to wysota for this useful post:

    magland (2nd October 2007)

Similar Threads

  1. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  2. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  3. Replies: 5
    Last Post: 4th August 2006, 23:44
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.