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:
void TableViewEx
::keyPressEvent( QKeyEvent *event
) {
if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) {
QApplication::clipboard()->setText
( this
->currentIndex
().
data().
toString() );
}
else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_P) {
model
()->setData
( currentIndex
(),
QApplication::clipboard()->text
() );
}
else {
}
}
void TableViewEx::keyPressEvent( QKeyEvent *event )
{
if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) {
QApplication::clipboard()->setText( this->currentIndex().data().toString() );
}
else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_P) {
model()->setData( currentIndex(), QApplication::clipboard()->text() );
}
else {
QTableView::keyPressEvent(event);
}
}
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
Bookmarks