How QScrollArea repaints QWidget on it?
Solved
General and Desktop
-
Hi,
I have QScrollArea and one big widget ( inherits QWidget ) on it, like this:area = new QScrollArea(this); bigWidget = new bigWidgetClass; bigWidget->setFixedSize(5000,5000); area->setWidget(bigWidget);
In bigWidget I draw numbers, like this:
void bigWidgetClass::paintEvent(QPaintEvent *event) { QPainter painter(this); auto reg = visibleRegion(); for(int i=0; i<400; i++) { for(int j=0;j<400;j++) { if(reg.contains(QPoint(j*30,i*30))) { painter.drawText(j*30,i*30,QString::number((i)%10000)); } } } }
I check if point is visible - drawText. If not - don't drawText:
if(reg.contains(QPoint(j*30,i*30)))
I would like not to draw text, which I will don't see on screen, because I would like to have faster application.When I change QScrollArea's ScrollBar value using mouse I don't see all text pixels:
When I minimize application, and next show it - everything is ok ( I see all text pixels ).
So how QScrollArea repaint screen? Using repaint(QRegion) ?
-
Quick dirty example:
class BigWidget : public QWidget { void paintEvent(QPaintEvent *event) { QPainter painter(this); auto reg = visibleRegion(); int w=80; QSize s{w,w}; QPoint pv=reg.boundingRect().topLeft(); QRect rv(pv,s); while(reg.intersects(rv)) { painter.drawRect(rv); painter.drawText(rv, Qt::AlignCenter,QString("%1,%2").arg(rv.x()).arg(rv.y())); QPoint ph=pv+QPoint(w,0); QRect rh=QRect(ph,s); while(reg.intersects(rh)) { qDebug()<<rh; painter.drawRect(rh); painter.drawText(rh, Qt::AlignCenter,QString("%1,%2").arg(rh.x()).arg(rh.y())); ph+=QPoint(w,0); rh=QRect(ph,s); } pv+=QPoint(0,w); rv=QRect(pv,s); } } };