免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 964 | 回复: 0
打印 上一主题 下一主题

Layout Management [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-07 18:15 |只看该作者 |倒序浏览

                  Qt provides several classes that lay out widgets on a form: QHBoxLayout, QVBoxLayout, QGridLayout, and QStackLayout.Other classes that perform layout management include QSplitter,QScrollArea,QMainWindow,and QWorkSpace.  A widget's size policy tells the layout system how it should stretch or shrink. Qt provides sensible default size policies for all its built-in widgets,but since no single default can account for every possible layout,it is still common for developers to change the size policies for one or two widgets on a form.A QSizePolicy has both a horizontal and a Vertical component.Here are the most useful values:  (1) Fixed  means that the widget cannot grow or shrink.The widget always stays      at the size of its size hint.  (2) Minimum  means that the widget's size hint is its minimum size.The widget       cannot shrink below the size hint,but it can grow to fill available space       if necessary.  (3) Maximum  means that the widget's size hint is its maximum size.The widget      can be shrunk down to its minimum size hint.  (4) Preferred  means that the widget's size hint is its preferred size,but that      the widget can still shrink or grow if necessary.  (5) Expanding  means that the widget can shrink or grow and it is especially       willing to grow.  (6) Ignore is similar to Expanding,except that it ignores the widget's size       hint and minimum size hint.   The difference between Preferred and Expanding is that when a form that containsboth Preferred and Expanding widgets is resized,extra space is given to the Expandingwidgets,while the Preferred widgets stay at their size hint.   In addition to the size policy's horizontal and vertical components,the QSizePolicy class stores a horizontal and a vertical stretch factor.These stretch factors can be used to indicate that different child widgets should grow at different rates when the form expands.   Yet another way of influcening a layout is to set a minimum size,a maximum size,or a fixed size on the child widgets.  Splitters  A Qsplitter is a widget that contains other widgets.The widgets in a splitter areseperated by splitter handles.Users can change the sizes of a splitter's child widgets by dragging the handles.Splitters can often be used as an alternative to layout managers,to give more control to the user.For example:int main(int argc,char *argv[])
{
  QApplication app(argc,argv);  QTextEdit *editor1 = new QTextEdit;  QTextEdit *editor2 = new QTextEdit;  QTextEdit *editor3 = new QTextEdit;  QSplitter splitter(Qt::Horizontal);  splitter.addWidget(editor1);  splitter.addWidget(editor2);  splitter.addWidget(editor3);  
...  splitter.show(); 
return app.exec();
}
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/50916/showart_416822.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP