I'm using a QTableView where I show a list of Icons, the user can select some icons with mouse and control key button, and I'm able to handle these selections. But I want to disable the use of shift+left mouse key over the QTableView.
Is there any way to totally disable the shift key button during the process when GUI is being run? I am able to detect the shift key pressing using the eventFilter that is installed on the viewport of QTableView, but I cannot find any way to totally make the shift key inactive when the user presses shift key and the left mouse button together.
My event filter is as below:
bool MainWindow::eventFilter(QObject* obj, QEvent *ev)
{
if(obj == ui->listOfImages->viewport())
{
if(ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent * mouseEv = static_cast<QMouseEvent*>(ev);
if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == true) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == false))
{
controlButtonCounter++;
fetch = true;
//I use these variables for some purposes.
return QObject::eventFilter(obj,ev);
}
else if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == false) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == false))
{
if(selectedImages.size()>0)
{
ui->listOfImages->clearSelection();
selectedImages.clear();
selectedList.clear();
ui->selectedFiles->clear();
ui->selectedFiles->show();
}
fetch = false;
controlButtonCounter = 0;
//I use these variables for some purposes.
}
else if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == false) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == true) )
{
qDebug()<<"Shift button pressed!";
// Don't how to prevent shift button from selecting multiple icon.
}
}
}
return QObject::eventFilter(obj,ev);
}