• 10037阅读
  • 0回复

QScrollArea setWidget效率问题 [复制链接]

上一主题 下一主题
离线zjhcool
 
只看楼主 倒序阅读 楼主  发表于: 2010-11-12
— 本帖被 XChinux 执行加亮操作(2010-11-12) —


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重新编辑 ]
我的博客地址: http://newfaction.net
快速回复
限100 字节
 
上一个 下一个