Results 1 to 3 of 3

Thread: Detecting where "Paste" should paste to

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Detecting where "Paste" should paste to

    Hi, I have a question. Say I have an edit menu in my application, with different commands such as copy, paste, etc. When an object without text input has focus, I want the menu items in the edit menu disabled. And since I have multiple objects that accept input, I want the menu items to act on the active object, only if it accepts input.

    Any ideas on how to do this would be greatly appreciated. I see QCreator does it but I couldn't really find anything helpful in the huge code.

    Thanks in advance,
    codeslicer

  2. #2
    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: Detecting where "Paste" should paste to

    You might use QApplication::focusChanged to get the widget in focus and typecast the widget to desired text input classes like line edit, textedit etc, and update your menu item accordingly.

    You might also check if the widget has "text" property and perform actions using it.

  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: Detecting where "Paste" should paste to

    use QApplication::focusChanged() signal to detect when focus changes

    To check if actions should be enabled or not, you may check FocusPolicy - widgets without text input have usually set noFocus or tabFocus while editable items have often strong focus.

    You can also use qobject_cast<>() to determine if widget is a derrived from particullar class i.e. QAbstractSpinbox, QLineEdit, QTextEdit, QComboBox an so on.

    Next thing to do would be propagating copy, paste actions to focused widgets. I would suggest to create proper QShortcutEvent in each action and post it to focused widget with qApp->postEvent().

    Take also into consideration that using keyboard sequences like ctrl+C should work on focused widget(if it accepts such keysequence) without any additional implementations, because qt tries to deliver shortcutEvents to focused widget first and if it fails(widget doesn't accept a shortcut) it's delivered to widgets that are higher in hierarchy (so finally it reaches main window and it's menubar).
    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.