[英]QPaintEvent painting region in Qt?
This is a basic doubt regarding the Painting
done in Qt. 这是有关在Qt中完成
Painting
的基本疑问。 I have a QScrollArea
as my centralWidget
in Main Window
of my Application. 我的应用程序
Main Window
中有一个QScrollArea
作为我的centralWidget
。 I have added a QFrame
frame
to the scrollarea
. 我已经将
QFrame
frame
添加到scrollarea
。 The Layout
of the QFrame
is QGridLayout
. QFrame
的Layout
是QGridLayout
。 When I add widgets
to the layout
like this: 当我将
widgets
添加到layout
如下所示:
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? 将小部件添加到布局期间
disabled
设置更新是否有帮助?
Even if I maximise the window not all the QLabel's will be visible to me. 即使将窗口最大化,我也看不到所有的QLabel。 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?
因此,当代码流离开上面的函数并转到事件循环时,是否所有QLabel和QFrame的巨大区域都被绘制了? Or only those QLabel's which are visible & only that much area of QFrame which is visible painted?
还是仅那些可见的QLabel和仅可见的QFrame的大部分区域被涂上?
If you are using a form (.ui) then the widgets inside the ui
are not children of your widget MainWindow
. 如果您使用的是表单(.ui),则
ui
内的窗口小部件不是窗口小部件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
. 好吧,
setUpdatesEnabled()
仅影响当前的小部件及其子级,因此对象ui->frame
在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();
因此,您无需调用
repaint();
on any widget. 在任何小部件上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.