QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand ( const QModelIndex & index, const QEvent * event = 0 ) const
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *ev = 0) const { //ev->type(): 2/3/4/5 mouse: press/release/DblPress/move ; 6,7: Keyboard QList<int> mEvt;mEvt<<2<<3<<4<<5; if (mEvt.contains( ev->type() )) { const QMouseEvent* Mev = static_cast<const QMouseEvent*>(ev); mEvt[0]= Mev->type(); //2/3/4/5 mouse: press/release/DblPress/move mEvt[1]= Mev->buttons();//0/1/2/4 mouse: NoBtn/LB/RB/MB mEvt[2]= Mev->x();mEvt[3]= Mev->y();//x,y } else return QAbstractItemView::selectionCommand ( index, ev );//--- Mouse event occur ---- // TEST { QString str = QVariant(index.data()).toString();//QTreeView item data str +="(";str +=QString::number(index.row());str +=",";str +=QString::number(index.column());str +=") event:";//Selected item (Column,Row) for (int i=0;i<4;i++){ str += QString::number(mEvt[i]);str += ";";//Mouse: Function/Btn/(x,y) } emit SetTitle(str);//signal ... // TEST } if (((index.row()|index.column())<0) && mEvt[3] > 50)// out of index / out of (y)position - Clear All return (QItemSelectionModel::Clear); if (mEvt[1] & Qt::LeftButton) return (QItemSelectionModel::Select|QItemSelectionModel::Rows); if (mEvt[1] & (Qt::RightButton|Qt::MidButton)) return (QItemSelectionModel::Clear); //default by Parent return QAbstractItemView::selectionCommand ( index, ev ) ; }