Results 1 to 4 of 4

Thread: Overriding shortcuts for QGraphicsItems

  1. #1
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Overriding shortcuts for QGraphicsItems

    Hi Everyone.

    I've got an app that has the ability to create editable text box graphics items. Now I have the problem that I need actions to work differently depending on whether an item is currently being edited.

    For example, the copy action can either copy selected text or copy a whole box, depending on whether text is being edited or not. Same with delete, select all, etc.

    So far I've just been creating menu actions that select all items and such, and then overriding QGraphicsScene::keyPressEvent and checking if a box is being edited (and then ignoring keypresses like del). This isn't a very good solution, as I need to check every possible action, and it doesn't handle the scenario of the user selecting actions with the mouse.

    So it seems there should be something better. I was looking at the ShortcutOverride events, but I'm not sure how to use them.. My GraphicsScene doesn't get any of those types of events.

    IS there something basic I'm missing? How can I make actions do two different things based on an editing text graphics item without checking manually every time? Is there built in support for this? Thanks.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Overriding shortcuts for QGraphicsItems

    To copy a full box you must serialise a class from data
    have a look on ...
    http://www.qt-apps.org/content/show....?content=80234
    it can drag drop text image inside a bok or self... or drag image from firefox to box..
    I write this to build a html editor inside a CMS and as item from the new version of
    MiniScribus http://code.google.com/p/fop-miniscribus/ xsl-fo file .

  3. #3
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Overriding shortcuts for QGraphicsItems

    Sorry, my question was probably not very clear. The box copying is not the problem.

    The problem is that a QGraphicsTextItem uses several keyboard shortcuts to work with text. For example Ctrl-A will select all text, then you have the standard Ctrl-C/X/V to cut copy paste. Now in my mainwindow I have these same actions defined (cut, copy, select all) and they have the same keyboard shortcut. I defined those actions so that users could manipulate boxes with them. Now my actions are overriding those of the QGraphicsTextItem, so that when I press Ctrl-C while editing text, it triggers my copy action, instead of the text item's.

    So it boils down to: Can I avoid my window-level shortcuts overriding the shortcuts in QGraphicsTextItem?

  4. #4
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Overriding shortcuts for QGraphicsItems

    Ok. I ended up solving this in the following way:
    Override event(QEvent*) in the QGraphicsView class, check for a ShortcutOverride event, and then if an item is being edited and the shortcut is one of the common text editing shortcuts, accept the event so it won't be handled by the mainwindow.

Similar Threads

  1. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.