Results 1 to 12 of 12

Thread: Cut/Copy/Paste overrider shortcuts

  1. #1
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Cut/Copy/Paste overrider shortcuts

    Hi,

    Problem occurs when application have cut/copy/paste actions in menu (with shortcuts definded) and there are some widgets in the same window that need to react on that shortcuts in a different way.
    Widgets are implemented in library that is shared between view projects so it have to be free of application contexts. In addition those widgets are used in plugin so cut/copy/paste can't be invoked from mainWiddow's actions (because main window don't know what's in plugins).

    I need a way to catch ctrl+X/C/V shortcuts in widget and prevent them to be delivered to mainWindow's actions. I tried to add actions with different shortcut contexts to widget but it doesn't work. Then i tried to catch QEvent::ShortcutOverride in event or eventFilter and those events can be catched but even if i return true, mainwindow's action is called after widgets one and overrides clipboard contents.

    I have a temporary solution - i'm processing ShortcutOverride event, by posting userEvent to the same widget, let Qt invoke mainwindows action and then do own i.e. copy action when widget gets userEvent.

    I works, but i have a feeling that there have to be easier & more optimal way to achieve such behavior. Does anyone have some suggestions?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    I need a way to catch ctrl+X/C/V shortcuts in widget and prevent them to be delivered to mainWindow's actions. I tried to add actions with different shortcut contexts to widget but it doesn't work. Then i tried to catch QEvent::ShortcutOverride in event or eventFilter and those events can be catched but even if i return true, mainwindow's action is called after widgets one and overrides clipboard contents.
    But the order of events is the other way around... The main window forwards the events to its children and so on...

  3. #3
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    Quote Originally Posted by marcel View Post
    But the order of events is the other way around... The main window forwards the events to its children and so on...
    I don't really care how it flows inside, all i know is that in single event processed when shortcut is triggered, widget gets shortcutOverride event, then mainWidows action's triggered signal is emitted. I can't prevent action triggering when reacting on shortcutOverride so even if i'll copy something to clipboard, mainwindows action will overwrite clipboard with new inaccurate contents.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  4. #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: Cut/Copy/Paste overrider shortcuts

    Quote Originally Posted by marcel View Post
    But the order of events is the other way around... The main window forwards the events to its children and so on...
    Hmm... are you sure?

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    Hmm... are you sure?
    Well, not anymore.
    For certain types of events (e.g. mouse and key events), the event will be propagated to the receiver's parent and so on up to the top-level object if the receiver is not interested in the event (i.e., it returns false).

  6. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    The order of event propagation have nothing to do in this case.
    Important thing is that first event is processed to widgets(no matter how) then mainwindow's action is triggered and destroys clipboard contents set up by widget.

    This architecture causes that i'm unable to prevent action from execution when i'm setting clipboard contents in widget. Is there any way to have contextual clipboard support with actions in main menu?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  7. #7
    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: Cut/Copy/Paste overrider shortcuts

    Quote Originally Posted by mchara View Post
    This architecture causes that i'm unable to prevent action from execution when i'm setting clipboard contents in widget. Is there any way to have contextual clipboard support with actions in main menu?
    Have a single "copy" action that when triggered will forward the signal to a slot in an appropriate context.

    BTW. You should never have two same shortcuts when one of them is global (application or system wide).

  8. #8
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    Quote Originally Posted by mchara View Post
    Widgets are implemented in library that is shared between view projects so it have to be free of application contexts. In addition those widgets are used in plugin so cut/copy/paste can't be invoked from mainWiddow's actions (because main window don't know what's in plugins).
    So, it's possible and it's one of alternatives, but requires lots of coding in plugins management class so it's something that we don't want to do unless have no choice.

    Currently widgets reacts on shortcutOverride event and global shortcut checks focused widgets and works only if focus is on centrain application dependent widgets. This aproach seems to work fine, but still it's a bit workaround over qt mechanisms, so i'm trying to find better way without need to implementing it in pluginsManager.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    Will installing event filters help you ??

  10. #10
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cut/Copy/Paste overrider shortcuts

    shortcutOverride event is catched in eventFilter - it's only place it can be done cause there's no shortcutOverrideEvent method.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  11. #11
    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: Cut/Copy/Paste overrider shortcuts

    Have you tried simply using QShortcut? At worst it should trigger with QShortcut::activatedAmbiguously().

  12. #12
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cut/Copy/Paste overrider shortcuts (solved)

    I tried with QShortcut earlier with no effects.
    I didn't checked activatedAmbiguously, but manual says
    This signal is emitted when the user types a shortcut key sequence that is ambiguous. For example, if one key sequence is a "prefix" for another and the user types these keys it isn't clear if they want the shorter key sequence, or if they're about to type more to complete the longer key sequence.
    so i'm not sure if this is my case, my shortcuts are not ambiguous, they are rather overridden(but i have to admit that i didn't actually checked it)

    My last solution
    Currently widgets reacts on shortcutOverride(in eventFilter) event and global shortcut checks focused widgets and works only if focus is on centrain application dependent widgets.
    was accepted so i'm working on other tasks now, lets say current implementation is good enought and don't have to be ideal.

    I'll try to check activatedAmbiguously signal when i'll find some free time and i'll let you know if it helped.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

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.