Fix render lag in widgets resizeEvent()->show().

ScrollArea calls show() in ScrollBar::resizeEvent. If this event
handlers was called from SendPending...() you could set fake .._Shown
attribute on, call resizeEvent() and remove this attribute even if it
should not be removed already - after call to show().
This commit is contained in:
John Preston 2017-11-24 17:05:15 +04:00
parent 4b1d15f968
commit 9eacb11f3c
1 changed files with 11 additions and 4 deletions

View File

@ -138,7 +138,7 @@ void CreateWidgetStateRecursive(not_null<QWidget*> target) {
}
}
void SendPendingEventsRecursive(QWidget *target) {
void SendPendingEventsRecursive(QWidget *target, bool parentHiddenFlag) {
auto wasVisible = target->isVisible();
if (!wasVisible) {
target->setAttribute(Qt::WA_WState_Visible, true);
@ -153,6 +153,12 @@ void SendPendingEventsRecursive(QWidget *target) {
QResizeEvent e(target->size(), QSize());
QApplication::sendEvent(target, &e);
}
auto removeVisibleFlag = [&] {
return parentHiddenFlag
|| target->testAttribute(Qt::WA_WState_Hidden);
};
auto &children = target->children();
for (auto i = 0; i < children.size(); ++i) {
auto child = children[i];
@ -162,11 +168,12 @@ void SendPendingEventsRecursive(QWidget *target) {
if (!widget->testAttribute(Qt::WA_WState_Created)) {
WidgetCreator::Create(widget);
}
SendPendingEventsRecursive(widget);
SendPendingEventsRecursive(widget, removeVisibleFlag());
}
}
}
if (!wasVisible) {
if (removeVisibleFlag()) {
target->setAttribute(Qt::WA_WState_Visible, false);
}
}
@ -178,7 +185,7 @@ void myEnsureResized(QWidget *target) {
return;
}
CreateWidgetStateRecursive(target);
SendPendingEventsRecursive(target);
SendPendingEventsRecursive(target, !target->isVisible());
}
QPixmap myGrab(TWidget *target, QRect rect, QColor bg) {