Results 1 to 3 of 3

Thread: Copying contents of QTableView cell to clipboard

  1. #1
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Copying contents of QTableView cell to clipboard

    Hi,

    I have QTableView object which is responsible for displaying data from my own model. I want to be able to copy the contents of the table cell into the clipboard. How can I implement this?

    One possible solution is to create my own delegate (which iherits QItemDelegate) which allows editing the cells via QLineEdit. If I can edit then I can copy to the clipboard. But probably there is more simple solution?

    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Copying contents of QTableView cell to clipboard

    Override/catch keyPressEvent for the table view, check for appropriate key combination (Qt::ControlModifier, Qt::Key_C) , and use something like:
    Qt Code:
    1. QApplication::clipboard()->setText(tableView->currentIndex().data().toString())
    To copy to clipboard, switch view to plain text mode 

    The problem with item delegate's editor is that the user would naturally be able to copy only in editing mode..
    J-P Nurmi

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

    Conel (18th April 2006)

  4. #3
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Copying contents of QTableView cell to clipboard

    This works! Thanks a lot

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.