前言
QWidget实际上就是个壳,用来标记脏区域,处理一些事件。
1、首先update, repaint 最终都调用
QWidgetPrivate::syncBackingStore,
2、QWidgetPrivate::syncBackingStore 相关流程,最终调用endPaint进入平台层 , 调入void QFbBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset)
1 QBackingStore::flush qbackingstore.cpp 117 0x1189bd4f
2 QWidgetBackingStore::qt_flush qwidgetbackingstore.cpp 154 0x7b541dc
3 QWidgetBackingStore::flush qwidgetbackingstore.cpp 1400 0x7b5618a
4 QWidgetBackingStore::endPaint qwidgetbackingstore.cpp 359 0x7b563c5
5 QWidgetBackingStore::doSync qwidgetbackingstore.cpp 1384 0x7b579da
6 QWidgetBackingStore::sync qwidgetbackingstore.cpp 1162 0x7b57df3
7 QWidgetPrivate::syncBackingStore qwidget.cpp 1973 0x7b716e8
3、paintEvent相关调用流程
1 QWidget::event qwidget.cpp 9055 0x1443b556
2 Widget::event widget.cpp 29 0x401d0f
3 QApplicationPrivate::notify_helper qapplication.cpp 3722 0x143f85be
4 QApplication::notify qapplication.cpp 3685 0x14401f5b
5 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1024 0x1183057
6 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 236 0x144336ee
//这里发送 QEvent::Paint
7 QWidgetPrivate::sendPaintEvent qwidget.cpp 5715 0x144336ee
8 QWidgetPrivate::drawWidget qwidget.cpp 5655 0x1443423d
9 QWidgetBackingStore::doSync qwidgetbackingstore.cpp 1381 0x144079b4
10 QWidgetBackingStore::sync qwidgetbackingstore.cpp 1136 0x14407c59
11 QWidgetPrivate::syncBackingStore qwidget.cpp 1982 0x14421667
paintEvent 在 endPaint之前,如果在paintEvent里就开始传出画面,这时候最新的画面还没有刷出来
// Paint the rest with composition.
if (repaintAllWidgets || !dirtyCopy.isEmpty()) {
const int flags = QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawRecursive;
//这里会最终会调用painterEvent
tlw->d_func()->drawWidget(store->paintDevice(), dirtyCopy, tlwOffset, flags, 0, this);
}
4、endPaint里才是真是的绘制
endPaint(toClean, store, &beginPaintInfo);
case QEvent::Paint:
// At this point the event has to be delivered, regardless
// whether the widget isVisible() or not because it
// already went through the filters
paintEvent((QPaintEvent*)event);
break;