Results 1 to 3 of 3

Thread: Copy/Paste in TableView

  1. #1
    Join Date
    Sep 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Copy/Paste in TableView

    Hi all,

    I am using a model/view/delegate and I subclass QTableView to reimplement keyPressEvent(QKeyEvent *event) to catch ctrl-c and ctrl-v. I use the clipboard to copy the text at the currentIndex() and paste the results with model->setData(..). The method looks like this:

    Qt Code:
    1. void TableViewEx::keyPressEvent( QKeyEvent *event )
    2. {
    3. if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) {
    4.  
    5. QApplication::clipboard()->setText( this->currentIndex().data().toString() );
    6.  
    7. }
    8. else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_P) {
    9.  
    10. model()->setData( currentIndex(), QApplication::clipboard()->text() );
    11.  
    12. }
    13. else {
    14.  
    15. QTableView::keyPressEvent(event);
    16.  
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    The problem I'm having is that pasting text into a table-cell does not occur unless I use the Shift key also [CTRL-Shift-P].

    Any ideas what might be causing this?

    Added code tags/e8johan
    Last edited by e8johan; 10th September 2006 at 10:44.

  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 in TableView

    Maybe the CTRL+P combination is already assigned somewhere? Have you tried using CTRL+V?

  3. #3
    Join Date
    Sep 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Copy/Paste in TableView

    Hi,

    After changing keyPressEvent(..) to catch CTRL+V,

    else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_V)

    copy/paste works as expected.

    As it turns out, the original post used Qt::Key_P which is a post-midnight coding bug. Using that catch, paste works using CTRL+P.

    Thanks.

Similar Threads

  1. TreeView, TableView
    By rbrand in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 08:54
  2. Modified tableview
    By dkite in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2006, 01:58
  3. How to set the alignment in a TableView?
    By vratojr in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2006, 13:21
  4. Widgets in TableView
    By boonie in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 19:55
  5. I can't assign TableView signals...
    By tomek in forum Newbie
    Replies: 5
    Last Post: 9th January 2006, 21:04

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.