⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qabstractitemview.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  \since 4.2  \sa showDropIndicator dragDropOverwriteMode*/void QAbstractItemView::setDragDropMode(DragDropMode behavior){    Q_D(QAbstractItemView);    d->dragDropMode = behavior;    setDragEnabled(behavior == DragOnly || behavior == DragDrop || behavior == InternalMove);    setAcceptDrops(behavior == DropOnly || behavior == DragDrop || behavior == InternalMove);}QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode() const{    Q_D(const QAbstractItemView);    DragDropMode setBehavior = d->dragDropMode;    if (!dragEnabled() && !acceptDrops())        return NoDragDrop;    if (dragEnabled() && !acceptDrops())        return DragOnly;    if (!dragEnabled() && acceptDrops())        return DropOnly;    if (dragEnabled() && acceptDrops()) {        if (setBehavior == InternalMove)            return setBehavior;        else            return DragDrop;    }    return NoDragDrop;}#endif // QT_NO_DRAGANDDROP/*!  \property QAbstractItemView::alternatingRowColors  \brief whether to draw the background using alternating colors  If this property is true, the item background will be drawn using  QPalette::Base and QPalette::AlternateBase; otherwise the background  will be drawn using the QPalette::Base color.  By default, this property is false.*/void QAbstractItemView::setAlternatingRowColors(bool enable){    Q_D(QAbstractItemView);    d->alternatingColors = enable;    if (isVisible())        d->viewport->update();}bool QAbstractItemView::alternatingRowColors() const{    Q_D(const QAbstractItemView);    return d->alternatingColors;}/*!    \property QAbstractItemView::iconSize    \brief the size of items    Setting this property when the view is visible will cause the    items to be laid out again.*/void QAbstractItemView::setIconSize(const QSize &size){    Q_D(QAbstractItemView);    if (size == d->iconSize)        return;    d->iconSize = size;    d->doDelayedItemsLayout();}QSize QAbstractItemView::iconSize() const{    Q_D(const QAbstractItemView);    return d->iconSize;}/*!    \property QAbstractItemView::textElideMode    \brief the the position of the "..." in elided text.*/void QAbstractItemView::setTextElideMode(Qt::TextElideMode mode){    Q_D(QAbstractItemView);    d->textElideMode = mode;}Qt::TextElideMode QAbstractItemView::textElideMode() const{    return d_func()->textElideMode;}/*!  \reimp*/bool QAbstractItemView::focusNextPrevChild(bool next){    Q_D(QAbstractItemView);    if (d->tabKeyNavigation) {        QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier);        keyPressEvent(&event);        if (event.isAccepted())            return true;    }    return QAbstractScrollArea::focusNextPrevChild(next);}/*!  \reimp*/bool QAbstractItemView::event(QEvent *event){    Q_D(QAbstractItemView);    switch (event->type()) {    case QEvent::LocaleChange:        viewport()->update();        break;    case QEvent::LayoutDirectionChange:    case QEvent::ApplicationLayoutDirectionChange:        updateGeometries();        break;    case QEvent::StyleChange:        doItemsLayout();        break;    case QEvent::FocusOut:        d->checkPersistentEditorFocus();        break;    default:        break;    }    return QAbstractScrollArea::event(event);}/*!    \fn bool QAbstractItemView::viewportEvent(QEvent *event)    This function is used to handle tool tips, and What's    This? mode, if the given \a event is a QEvent::ToolTip,or a    QEvent::WhatsThis. It passes all other    events on to its base class viewportEvent() handler.*/bool QAbstractItemView::viewportEvent(QEvent *event){    Q_D(QAbstractItemView);    switch (event->type()) {    case QEvent::HoverEnter: {        QHoverEvent *he = static_cast<QHoverEvent*>(event);        d->hover = indexAt(he->pos());        d->viewport->update(visualRect(d->hover));        break; }    case QEvent::HoverLeave: {        d->viewport->update(visualRect(d->hover)); // update old        d->hover = QModelIndex();        break; }    case QEvent::HoverMove: {        QHoverEvent *he = static_cast<QHoverEvent*>(event);        QModelIndex old = d->hover;        d->hover = indexAt(he->pos());        if (d->hover != old)            d->viewport->update(visualRect(old)|visualRect(d->hover));        break; }    case QEvent::Leave:        d->enteredIndex = QModelIndex();        break;    case QEvent::ToolTip:    case QEvent::QueryWhatsThis:    case QEvent::WhatsThis: {        QHelpEvent *he = static_cast<QHelpEvent*>(event);        const QModelIndex index = indexAt(he->pos());        QStyleOptionViewItemV3 option = d->viewOptionsV3();        option.rect = visualRect(index);        option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);        bool retval = false;        // ### Qt 5: make this a normal function call to a virtual function        QMetaObject::invokeMethod(d->delegateForIndex(index), "helpEvent",                                  Q_RETURN_ARG(bool, retval),                                  Q_ARG(QHelpEvent *, he),                                  Q_ARG(QAbstractItemView *, this),                                  Q_ARG(QStyleOptionViewItem, option),                                  Q_ARG(QModelIndex, index));        return retval;    }    case QEvent::FontChange:        d->doDelayedItemsLayout(); // the size of the items will change        break;    case QEvent::WindowActivate:    case QEvent::WindowDeactivate:        d->viewport->update();        break;    default:        break;    }    return QAbstractScrollArea::viewportEvent(event);}/*!    This function is called with the given \a 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.*/void QAbstractItemView::mousePressEvent(QMouseEvent *event){    Q_D(QAbstractItemView);    QPoint pos = event->pos();    QPersistentModelIndex index = indexAt(pos);    if (!d->selectionModel        || (d->state == EditingState && d->hasEditor(index)))        return;    d->pressedAlreadySelected = d->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(currentIndex()).center() + offset;    if (edit(index, NoEditTriggers, event))        return;    if (index.isValid()) {        // we disable scrollTo for mouse press so the item doesn't change position        // when the user is interacting with it (ie. clicking on it)        bool autoScroll = d->autoScroll;        d->autoScroll = false;        d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);        d->autoScroll = autoScroll;    }    QRect rect(d->pressedPosition - offset, pos);    setSelection(rect, command);    // signal handlers may change the model    if (index.isValid()) {        emit pressed(index);        if (d->autoScroll) {            //we delay the autoscrolling to filter out double click event            //100 is to be sure that there won't be a double-click misinterpreted as a 2 single clicks            d->delayedAutoScroll.start(QApplication::doubleClickInterval()+100, this);        }    }}/*!    This function is called with the given \a event when a mouse move event is    sent to the widget. If a selection is in progress and new items are moved    over the selection is extended; if a drag is in progress it is continued.*/void QAbstractItemView::mouseMoveEvent(QMouseEvent *event){    Q_D(QAbstractItemView);    QPoint topLeft;    QPoint bottomRight = event->pos();    if (state() == ExpandingState || state() == CollapsingState)        return;#ifndef QT_NO_DRAGANDDROP    if (state() == DraggingState) {        topLeft = d->pressedPosition - d->offset();        if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) {            startDrag(d->model->supportedDragActions());            setState(NoState); // the startDrag will return when the dnd operation is done            stopAutoScroll();        }        return;    }#endif // QT_NO_DRAGANDDROP    QModelIndex index = indexAt(bottomRight);    QModelIndex buddy = d->model->buddy(d->pressedIndex);    if (state() == EditingState && d->hasEditor(buddy)        || edit(index, NoEditTriggers, event))        return;    if (d->selectionMode != SingleSelection)        topLeft = d->pressedPosition - d->offset();    else        topLeft = bottomRight;    if (d->enteredIndex != index) {        // signal handlers may change the model        QPersistentModelIndex persistent = index;        if (persistent.isValid()) {            emit entered(persistent);#ifndef QT_NO_STATUSTIP            QString statustip = d->model->data(persistent, Qt::StatusTipRole).toString();            if (parent() && !statustip.isEmpty()) {                QStatusTipEvent tip(statustip);                QApplication::sendEvent(parent(), &tip);            }#endif        } else {#ifndef QT_NO_STATUSTIP            if (parent()) {                QString emptyString;                QStatusTipEvent tip(emptyString);                QApplication::sendEvent(parent(), &tip);            }#endif            emit viewportEntered();        }        d->enteredIndex = persistent;        index = persistent;    }#ifndef QT_NO_DRAGANDDROP    if (index.isValid() && d->dragEnabled        && state() != DragSelectingState        && event->buttons() != Qt::NoButton) {        bool dragging = d->model->flags(index) & Qt::ItemIsDragEnabled;        bool selected = d->selectionModel->isSelected(index);        if (dragging && selected) {            setState(DraggingState);            return;        }    }#endif    if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) {        setState(DragSelectingState);        QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);        // Do the normalize ourselves, since QRect::normalized() is flawed        QRect selectionRect = QRect(topLeft, bottomRight);        QPersistentModelIndex persistent = index;        setSelection(selectionRect, command);        // set at the end because it might scroll the view        if (persistent.isValid())            d->selectionModel->setCurrentIndex(persistent, QItemSelectionModel::NoUpdate);    }}/*!    This function is called with the given \a event when a mouse button is released,    after a mouse press event on the widget. If a user presses the mouse inside your    widget and then drags the mouse to another location before releasing the mouse button,    your widget receives the release event. The function will emit the clicked() signal if an    item was being pressed.*/void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event){    Q_D(QAbstractItemView);    QPoint pos = event->pos();    QPersistentModelIndex index = indexAt(pos);    if (state() == EditingState) {        if (d->isIndexValid(index) && d->sendDelegateEvent(index, event))            d->viewport->update(visualRect(index));        return;    }    setState(NoState);    bool click = (index == d->pressedIndex && index.isValid());    bool selectedClicked = click && (event->button() & Qt::LeftButton) && d->pressedAlreadySelected;    EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);    bool edited = edit(index, trigger, event);    if (d->selectionModel)        d->selectionModel->select(index, selectionCommand(index, event));    if (click) {        emit clicked(index);        if (edited)            return;        if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this))            emit activated(index);    }}/*!    This function is called with the given \a event when a mouse button is    double clicked inside the widget. If the double-click is on a valid item it    emits the doubleClicked() signal and calls edit() on the item.*/void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -