Reputation: 5073
This is a basic doubt regarding the Painting
done in Qt.
I have a QScrollArea
as my centralWidget
in Main Window
of my Application. I have added a QFrame
frame
to the scrollarea
. The Layout
of the QFrame
is QGridLayout
.
When I add widgets
to the layout
like this:
MainWindow::AddLabel()
{
setUpdatesEnabled(false);
QGridLayout *myGrid = (QGridLayout *)ui->frame->layout();
for(int i = 0; i < 1000; i++)
{
QLabel *label = new QLabel();
QString str;
str.SetNum(i);
label->SetText(str);
myGrid->AddWidget(label, 0, i, 0);//add label to i'th column of row 0
}
setUpdatesEnabled(true);
repaint();
}
Please dont worry about the memory leak as it is not the focus of the question. So my doubt's are:
Is setting the updates disabled
during adding widgets to layout any helpful?
Even if I maximise the window not all the QLabel's will be visible to me. So when the code flow leaves the above function & goes to the event loop then are all the QLabel's & the enormous area of QFrame painted? Or only those QLabel's which are visible & only that much area of QFrame which is visible painted?
Upvotes: 0
Views: 669
Reputation: 22890
If you are using a form (.ui) then the widgets inside the ui
are not children of your widget MainWindow
. Well , setUpdatesEnabled()
only affect the current widget as well as its children, so the object ui->frame
will still receive updates after myGrid->AddWidget
. Change to
ui->frame->setUpdatesEnabled(false);
...
ui->frame->setUpdatesEnabled(true);
Btw, when you enable updates, then screen will be updated. So you dont need to call repaint();
on any widget.
Upvotes: 1