QScrollArea 在实际使用过程中发现了个
Qt的Bug,
setWidget方法的
效率存在
问题。
首先先看QScrollArea setWidget的方法的官方说明Sets the scroll area’s
widget.
The widget becomes a child of the scroll area, and will be destroyedwhen the scroll area is deleted or when a new widget is set.
The widget’s autoFillBackground property will be set to true.
If the scroll area is visible when the widget is added, you must show() it explicitly.
Note that You must add the layout of widget before you call thisfunction; if you add it later, the widget will
not be visible –regardless of when you show() the scroll area. In this case, you canalso not show() the widget later.
QScrollArea setWidget BUG 的产生请对比以下两断代码:
//代码1
QScrollArea *scroll = new QScrollArea(this);
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
widget->setLayout(layout);
QWidget *child = new QWiget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
child = new QWidget;
layout->addWidget(child);
scroll->setWidget(widget);
show();原文链接
http://newfaction.net/2010/11/09/qscrollarea-setwidget-efficiency.html相关文章[ 此帖被zjhcool在2010-11-17 10:57重新编辑 ]