Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.4, 4.8.2, 5.4.0 Beta, 5.5.1, 5.9.1, 6.2
-
None
-
Windows 7, x64 (Intel i5), VS2008
Ubuntu 12.04 64-bit
-
22634e00794e72d68e7578e1962f9f2023870749 (qt/qtbase/dev) 94c2953aa9e1616e13d45ad60d37a793651491d4 (qt/qtbase/6.2)
Description
QScrollArea: The viewport bleeds through another widget when the scroll bar is reset.
(see the second screenshot).
Bar.java
#include <QApplication> #include <QScrollArea> #include <QPainter> #include <QPaintEvent> #include <QScrollBar> class CustomWidget : public QWidget { public: CustomWidget(const QColor &b, QWidget *parent = 0) : QWidget(parent), background(b) { } void paintEvent(QPaintEvent *e) { QPainter p(this); p.fillRect(e->rect(), background); } QColor background; }; class MainWidget : public QWidget { public: MainWidget(QWidget *parent = 0) : QWidget(parent) { area = new QScrollArea(this); area->setWidget(new CustomWidget(Qt::gray)); widget = new CustomWidget(Qt::red, this); timerId = startTimer(100); } void resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); area->resize(800, 100); area->widget()->resize(5000, 600); area->move((width() - area->width()) / 2, (height() - area->height()) / 2); widget->resize(500, 200); widget->move((width() - widget->width()) / 2, (height() - widget->height()) / 2); } void timerEvent(QTimerEvent *e) { if (e->timerId() == timerId) { if (area->horizontalScrollBar()->value() == area->horizontalScrollBar()->maximum()) area->horizontalScrollBar()->setValue(0); else area->horizontalScrollBar()->setValue(area->horizontalScrollBar()->value() + 200); } else { QWidget::timerEvent(e); } } private: QScrollArea *area; CustomWidget *widget; int timerId; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWidget w; w.showMaximized(); return app.exec(); }