Fix disappearing transient scrollbars
When a transient scrollbar is already at the end and user attempts to scroll further, the scrollbar is "flashed" to indicate that the scroll area is already scrolled to the end. This is done so that the scrollbar is first painted with a flag turned on to make it appear visible and then again with the flag turned off to make qstyle start fading it out. The previous code that relied on paint events to clear the flag was error prone, and caused the scrollbars to get stuck in an inconsistent state. This change makes sure that the flag gets cleared regardless of whether a paint event in each state is received or not. Task-number: QTBUG-37787 Change-Id: I907697c32cd4d55208a490804a221a5dd6bf7b0b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>bb10
parent
3c6c14c0bf
commit
123ae472e2
|
|
@ -248,8 +248,13 @@ void QScrollBarPrivate::flash()
|
|||
Q_Q(QScrollBar);
|
||||
if (!flashed && q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q)) {
|
||||
flashed = true;
|
||||
q->show();
|
||||
if (!q->isVisible())
|
||||
q->show();
|
||||
else
|
||||
q->update();
|
||||
}
|
||||
if (!flashTimer)
|
||||
flashTimer = q->startTimer(0);
|
||||
}
|
||||
|
||||
void QScrollBarPrivate::activateControl(uint control, int threshold)
|
||||
|
|
@ -386,6 +391,7 @@ void QScrollBarPrivate::init()
|
|||
pointerOutsidePressedControl = false;
|
||||
transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q);
|
||||
flashed = false;
|
||||
flashTimer = 0;
|
||||
q->setFocusPolicy(Qt::NoFocus);
|
||||
QSizePolicy sp(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::Slider);
|
||||
if (orientation == Qt::Vertical)
|
||||
|
|
@ -476,6 +482,7 @@ void QScrollBar::sliderChange(SliderChange change)
|
|||
*/
|
||||
bool QScrollBar::event(QEvent *event)
|
||||
{
|
||||
Q_D(QScrollBar);
|
||||
switch(event->type()) {
|
||||
case QEvent::HoverEnter:
|
||||
case QEvent::HoverLeave:
|
||||
|
|
@ -486,6 +493,16 @@ bool QScrollBar::event(QEvent *event)
|
|||
case QEvent::StyleChange:
|
||||
d_func()->setTransient(style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this));
|
||||
break;
|
||||
case QEvent::Timer:
|
||||
if (static_cast<QTimerEvent *>(event)->timerId() == d->flashTimer) {
|
||||
if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)) {
|
||||
d->flashed = false;
|
||||
update();
|
||||
}
|
||||
killTimer(d->flashTimer);
|
||||
d->flashTimer = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -536,10 +553,6 @@ void QScrollBar::paintEvent(QPaintEvent *)
|
|||
opt.activeSubControls = (QStyle::SubControl)d->hoverControl;
|
||||
}
|
||||
style()->drawComplexControl(QStyle::CC_ScrollBar, &opt, &p, this);
|
||||
if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)) {
|
||||
d->flashed = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public:
|
|||
void setTransient(bool value);
|
||||
|
||||
bool flashed;
|
||||
int flashTimer;
|
||||
void flash();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue