Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

void QAbstractItemView::mousePressEvent ( QMouseEvent event  )  [protected, virtual, inherited]

This function is called with the given event when a mouse button is pressed while the cursor is inside the widget. If a valid item is pressed on it is made into the current item. This function emits the pressed() signal.

Reimplemented from QAbstractScrollArea.

Reimplemented in QHeaderView, and QTreeView.

Definition at line 960 of file qabstractitemview.cpp.

References QRect::center(), QAbstractItemView::currentIndex(), QAbstractItemView::edit(), QAbstractItemView::indexAt(), QItemSelectionModel::isSelected(), QModelIndex::isValid(), QRect::normalized(), QWidget::pos, QAbstractItemView::pressed(), QWidget::rect, QAbstractItemView::selectionCommand(), QAbstractItemView::selectionModel(), QItemSelectionModel::setCurrentIndex(), QAbstractItemView::setSelection(), and QAbstractItemView::visualRect().

Referenced by QTreeView::mousePressEvent().

    QPoint pos = event->pos();
    QModelIndex index = indexAt(pos);

    if (!selectionModel() || (d->state == EditingState && d->editors.contains(index)))

    bool alreadySelected = selectionModel()->isSelected(index);
    d->pressedIndex = index;
    d->pressedModifiers = event->modifiers();
    QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
    QPoint offset = d->offset();
    if ((command & QItemSelectionModel::Current) == 0)
        d->pressedPosition = pos + offset;
    if (d->pressedPosition == QPoint(-1, -1))
        d->pressedPosition = visualRect(selectionModel()->currentIndex()).center() + offset;
    QRect rect(d->pressedPosition - offset, pos);
    setSelection(rect.normalized(), command);
    if (index.isValid())
        selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);

    // signal handlers may change the model
    if (index.isValid()) {
        QPersistentModelIndex persistent = index;
        emit pressed(index);
        index = persistent;
        if (alreadySelected)
            edit(index, SelectedClicked, event);

Generated by  Doxygen 1.6.0   Back to index