PDA

View Full Version : Copying contents of QTableView cell to clipboard



Conel
18th April 2006, 12:01
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

jpn
18th April 2006, 12:23
Override/catch keyPressEvent for the table view, check for appropriate key combination (Qt::ControlModifier, Qt::Key_C) , and use something like:

QApplication::clipboard()->setText(tableView->currentIndex().data().toString())

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

Conel
18th April 2006, 15:50
This works! Thanks a lot