I have a QTableWidget and I would like to add some keyboard shortcuts so the user can move row items up and down.
I already have a keyboard shortcut for the "delete" button to delete a row working.
I tried to do a shortcut on the up and down arrow keys, but it did not work. I figure this is because QTableWidget is using those keys for navigation.
Therefore I wanted to use Alt+Key_Up and Alt+Key_Down, but that does not seem to work either. From the debugger, it seems like the event is being called when I press the Alt key before I have a chance to press up.
Here is some of my code:
void MainWindow
::keyPressEvent(QKeyEvent *event
) {
if (event->key()==Qt::Key_Delete)
// Delete row, this works fine
else if (event->modifiers()&Qt::AltModifier &&
(event->key()==Qt::Key_Up || event->key()==Qt::Key_Down))
// move row up or down, this does not work
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key()==Qt::Key_Delete)
// Delete row, this works fine
else if (event->modifiers()&Qt::AltModifier &&
(event->key()==Qt::Key_Up || event->key()==Qt::Key_Down))
// move row up or down, this does not work
}
To copy to clipboard, switch view to plain text mode
Bookmarks