[Qt-interest] QTableView multiple selection and D&D key modifiers??
James Vanns
james.vanns at framestore.com
Mon Jul 13 11:45:43 CEST 2009
Can it be done? I have sub-classed QTableView and enabled multiple item selection (rows only) so that we can use shift, ctrl. etc to select the items but then I also want to use the shift key as a D&D modifier. I.e. only drag is enabled when you hold down shift. Can this be done with Qt? I can't seem to get it to behave correctly. I override keyPressEvent and keyReleaseEvent to set a 'dragable' flag in the model (so that the flags() method can OR ItemIsDragEnabled) and then also call QTableView::keyPressEvent etc. to ensure normal behaviour is resumed afterward but this seems to mess up the selection after shift is pressed/released.
void
FQJobsViewWidget::keyPressEvent(QKeyEvent *p_event)
{
if (p_event->key() == Qt::Key_Shift)
m_model->enable_drag();
QTableView::keyPressEvent(p_event);
}
void
FQJobsViewWidget::keyReleaseEvent(QKeyEvent *p_event)
{
if (p_event->key() == Qt::Key_Shift)
m_model->disable_drag();
QTableView::keyReleaseEvent(p_event);
}
Has anyone got this to work with multiple item selection? Is there a better way of trying to achieve this?
Regards,
Jim Vanns
--
James Vanns
Software Engineer
Framestore Ltd.
More information about the Qt-interest-old
mailing list