📄 qabstractscrollarea.cpp
字号:
break; case QEvent::Paint: if (d->cornerPaintingRect.isValid()) { QStyleOption option; option.rect = d->cornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); }#ifdef Q_WS_MAC if (d->reverseCornerPaintingRect.isValid()) { QStyleOption option; option.rect = d->reverseCornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); }#endif QFrame::paintEvent((QPaintEvent*)e); break; case QEvent::ContextMenu: if (static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) return QFrame::event(e); e->ignore(); break; case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: case QEvent::Wheel:#ifndef QT_NO_DRAGANDDROP case QEvent::Drop: case QEvent::DragEnter: case QEvent::DragMove: case QEvent::DragLeave:#endif return false; case QEvent::StyleChange: case QEvent::LayoutDirectionChange: case QEvent::ApplicationLayoutDirectionChange: d->layoutChildren(); // fall through default: return QFrame::event(e); } return true;}/*! \fn bool QAbstractScrollArea::viewportEvent(QEvent *event) The main event handler for the scrolling area (the viewport() widget). It handles the \a event specified, and can be called by subclasses to provide reasonable default behavior. Returns true to indicate to the event system that the event has been handled, and needs no further processing; otherwise returns false to indicate that the event should be propagated further. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead. Specialised handlers for viewport events are: paintEvent(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), wheelEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), contextMenuEvent(), and resizeEvent().*/bool QAbstractScrollArea::viewportEvent(QEvent *e){ switch (e->type()) { case QEvent::Resize: case QEvent::Paint: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: case QEvent::ContextMenu:#ifndef QT_NO_WHEELEVENT case QEvent::Wheel:#endif#ifndef QT_NO_DRAGANDDROP case QEvent::Drop: case QEvent::DragEnter: case QEvent::DragMove: case QEvent::DragLeave:#endif return QFrame::event(e); case QEvent::LayoutRequest: return event(e); default: break; } return false; // let the viewport widget handle the event}/*! \fn void QAbstractScrollArea::resizeEvent(QResizeEvent *event) This event handler can be reimplemented in a subclass to receive resize events (passed in \a event), for the viewport() widget. When resizeEvent() is called, the viewport already has its new geometry: Its new size is accessible through the QResizeEvent::size() function, and the old size through QResizeEvent::oldSize(). \sa QWidget::resizeEvent() */void QAbstractScrollArea::resizeEvent(QResizeEvent *){}/*! \fn void QAbstractScrollArea::paintEvent(QPaintEvent *event) This event handler can be reimplemented in a subclass to receive paint events (passed in \a event), for the viewport() widget. \note If you open a painter, make sure to open it on the viewport(). \sa QWidget::paintEvent()*/void QAbstractScrollArea::paintEvent(QPaintEvent*){}/*! This event handler can be reimplemented in a subclass to receive mouse press events for the viewport() widget. The event is passed in \a e. \sa QWidget::mousePressEvent()*/void QAbstractScrollArea::mousePressEvent(QMouseEvent *e){ e->ignore();}/*! This event handler can be reimplemented in a subclass to receive mouse release events for the viewport() widget. The event is passed in \a e. \sa QWidget::mouseReleaseEvent()*/void QAbstractScrollArea::mouseReleaseEvent(QMouseEvent *e){ e->ignore();}/*! This event handler can be reimplemented in a subclass to receive mouse double click events for the viewport() widget. The event is passed in \a e. \sa QWidget::mouseDoubleClickEvent()*/void QAbstractScrollArea::mouseDoubleClickEvent(QMouseEvent *e){ e->ignore();}/*! This event handler can be reimplemented in a subclass to receive mouse move events for the viewport() widget. The event is passed in \a e. \sa QWidget::mouseMoveEvent()*/void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e){ e->ignore();}/*! This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widget. The event is passed in \a e. \sa QWidget::wheelEvent()*/#ifndef QT_NO_WHEELEVENTvoid QAbstractScrollArea::wheelEvent(QWheelEvent *e){ Q_D(QAbstractScrollArea); if (static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal) QApplication::sendEvent(d->hbar, e); else QApplication::sendEvent(d->vbar, e);}#endif/*! This event handler can be reimplemented in a subclass to receive context menu events for the viewport() widget. The event is passed in \a e. \sa QWidget::contextMenuEvent()*/void QAbstractScrollArea::contextMenuEvent(QContextMenuEvent *e){ e->ignore();}/*! This function is called with key event \a e when key presses occur. It handles PageUp, PageDown, Up, Down, Left, and Right, and ignores all other key presses.*/void QAbstractScrollArea::keyPressEvent(QKeyEvent * e){ Q_D(QAbstractScrollArea); if (false){#ifndef QT_NO_SHORTCUT } else if (e == QKeySequence::MoveToPreviousPage) { d->vbar->triggerAction(QScrollBar::SliderPageStepSub); } else if (e == QKeySequence::MoveToNextPage) { d->vbar->triggerAction(QScrollBar::SliderPageStepAdd);#endif } else {#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { e->ignore(); return; }#endif switch (e->key()) { case Qt::Key_Up: d->vbar->triggerAction(QScrollBar::SliderSingleStepSub); break; case Qt::Key_Down: d->vbar->triggerAction(QScrollBar::SliderSingleStepAdd); break; case Qt::Key_Left:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->minimum())) { //if we aren't using the hbar or we are already at the leftmost point ignore e->ignore(); return; }#endif d->hbar->triggerAction(QScrollBar::SliderSingleStepSub); break; case Qt::Key_Right:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->maximum())) { //if we aren't using the hbar or we are already at the rightmost point ignore e->ignore(); return; }#endif d->hbar->triggerAction(QScrollBar::SliderSingleStepAdd); break; default: e->ignore(); return; } } e->accept();}#ifndef QT_NO_DRAGANDDROP/*! \fn void QAbstractScrollArea::dragEnterEvent(QDragEnterEvent *event) This event handler can be reimplemented in a subclass to receive drag enter events (passed in \a event), for the viewport() widget. \sa QWidget::dragEnterEvent()*/void QAbstractScrollArea::dragEnterEvent(QDragEnterEvent *){}/*! \fn void QAbstractScrollArea::dragMoveEvent(QDragMoveEvent *event) This event handler can be reimplemented in a subclass to receive drag move events (passed in \a event), for the viewport() widget. \sa QWidget::dragMoveEvent()*/void QAbstractScrollArea::dragMoveEvent(QDragMoveEvent *){}/*! \fn void QAbstractScrollArea::dragLeaveEvent(QDragLeaveEvent *event) This event handler can be reimplemented in a subclass to receive drag leave events (passed in \a event), for the viewport() widget. \sa QWidget::dragLeaveEvent()*/void QAbstractScrollArea::dragLeaveEvent(QDragLeaveEvent *){}/*! \fn void QAbstractScrollArea::dropEvent(QDropEvent *event) This event handler can be reimplemented in a subclass to receive drop events (passed in \a event), for the viewport() widget. \sa QWidget::dropEvent()*/void QAbstractScrollArea::dropEvent(QDropEvent *){}#endif/*! This virtual handler is called when the scroll bars are moved by \a dx, \a dy, and consequently the viewport's contents should be scrolled accordingly. The default implementation simply calls update() on the entire viewport(), subclasses can reimplement this handler for optimization purposes, or - like QScrollArea - to move a contents widget. The parameters \a dx and \a dy are there for convenience, so that the class knows how much should be scrolled (useful e.g. when doing pixel-shifts). You may just as well ignore these values and scroll directly to the position the scroll bars indicate. Calling this function in order to scroll programmatically is an error, use the scroll bars instead (e.g. by calling QScrollBar::setValue() directly).*/void QAbstractScrollArea::scrollContentsBy(int, int){ viewport()->update();}void QAbstractScrollAreaPrivate::_q_hslide(int x){ Q_Q(QAbstractScrollArea); int dx = xoffset - x; xoffset = x; q->scrollContentsBy(dx, 0);}void QAbstractScrollAreaPrivate::_q_vslide(int y){ Q_Q(QAbstractScrollArea); int dy = yoffset - y; yoffset = y; q->scrollContentsBy(0, dy);}void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars(){ layoutChildren();}QPoint QAbstractScrollAreaPrivate::contentsOffset() const{ Q_Q(const QAbstractScrollArea); QPoint offset; if (vbar->isVisible()) offset.setY(vbar->value()); if (hbar->isVisible()) { if (q->isRightToLeft()) offset.setX(hbar->maximum() - hbar->value()); else offset.setX(hbar->value()); } return offset;}/*! \reimp*/QSize QAbstractScrollArea::minimumSizeHint() const{ Q_D(const QAbstractScrollArea); int hsbExt = d->hbar->sizeHint().height(); int vsbExt = d->vbar->sizeHint().width(); int extra = 2 * d->frameWidth; return QSize(d->scrollBarContainers[Qt::Horizontal]->sizeHint().width() + vsbExt + extra, d->scrollBarContainers[Qt::Vertical]->sizeHint().height() + hsbExt + extra);}/*! \reimp*/QSize QAbstractScrollArea::sizeHint() const{ return QSize(256, 192);#if 0 Q_D(const QAbstractScrollArea); int h = qMax(10, fontMetrics().height()); int f = 2 * d->frameWidth; return QSize((6 * h) + f, (4 * h) + f);#endif}/*! This slot is called by QAbstractScrollArea after setViewport(\a viewport) has been called. Reimplement this function in a subclass of QAbstractScrollArea to initialize the new \a viewport before it is used. \sa setViewport()*/void QAbstractScrollArea::setupViewport(QWidget *viewport){ Q_UNUSED(viewport);}#include "moc_qabstractscrollarea.cpp"#include "moc_qabstractscrollarea_p.cpp"#endif // QT_NO_SCROLLAREA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -