Hi ,all
Recently, I use tableview to make an alarm window which ,obviously, show the alarms in in the scada system.
The requirement is: If the operator is permitted by his privilege to ack the alarm in the alarm window,he can select the alarm, if not, he cannot select.
I inherit QTableView and rewrite the function
QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QModelIndex &index, const QEvent *event) const
To copy to clipboard, switch view to plain text mode
the code is like this:
{
if (the operator does not have privilege){
}
}
QItemSelectionModel::SelectionFlags CAckTableView::selectionCommand ( const QModelIndex & index, const QEvent * event) const
{
if (the operator does not have privilege){
return QItemSelectionModel::NoUpdate | QItemSelectionModel::current;
}
return QTableView::selectionCommand(index,event);
}
To copy to clipboard, switch view to plain text mode
Then I found the selcet event QEvent::MouseButtonPress act
properly,but QEvent::MouseMove is very strange.
The selection behavior of QEvent::MouseMove is depend on the last item the mouse pointer on. That is hard to describe clearly. Finally I probably find the problem in the qt source code. In
void QAbstractItemView::mouseMoveEvent(QMouseEvent *event)
To copy to clipboard, switch view to plain text mode
,
call
setSelection(selectionRect, command);
setSelection(selectionRect, command);
To copy to clipboard, switch view to plain text mode
,
the parameter is
if (d->selectionMode != SingleSelection)
topLeft = d->pressedPosition - d->offset();
else
topLeft = bottomRight;
QPoint bottomRight
= event
->pos
();
QRect selectionRect
= QRect(topLeft, bottomRight
);
QPoint topLeft;
if (d->selectionMode != SingleSelection)
topLeft = d->pressedPosition - d->offset();
else
topLeft = bottomRight;
QPoint bottomRight = event->pos();
QRect selectionRect = QRect(topLeft, bottomRight);
QModelIndex index = indexAt(bottomRight);
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
To copy to clipboard, switch view to plain text mode
In coclusion the problem is: the selection of MouseMove event is depend on whether the operator has the privilge on the last item the mouse pointed. The privilege cannot work!!
I think the problem is in the
void QAbstractItemView::mouseMoveEvent(QMouseEvent *event)
To copy to clipboard, switch view to plain text mode
.
Did anyone meet such problem? Please give me a clue! Thank you!
Bookmarks