Qt4--FormLayout
2015-07-10 09:10
447 查看
FormLayout显然对于Form非常适合。
QFormLayout *formLay=new QFormLayout;QLineEdit *name=new QLineEdit;
QLineEdit *email=new QLineEdit;
QLineEdit *address=new QLineEdit;
formLay->addRow(tr("&Name:"),name);
formLay->addRow(tr("&Email:"),email);
formLay->addRow(tr("&Address:"),address);
setLayout(formLay);
仅需要这些代码就可以显示如下:
formLay->setLabelAlignment(Qt::AlignRight);
formLay->setRowWrapPolicy(QFormLayout::WrapAllRows);(默认的是QFormLayout::DontWrapAllRows)之后变为
另外注意到tr("&Name:"),加这个'&'是什么意思呢,实际上在为一个Label setBuddy时必须加&,在FormLayout中自动把LineEdit设为Label的Buddy了。如果使用其他Layout需要用下面代码显示指定Buddy:
QLineEdit *nameEd = new QLineEdit(this); QLabel *nameLb = new QLabel("&Name:", this); nameLb->setBuddy(nameEd); QLineEdit *phoneEd = new QLineEdit(this); QLabel *phoneLb = new QLabel("&Phone:", this); phoneLb->setBuddy(phoneEd);
设置Buddy有神马用呢?当你按Alt+A时Address对应的LineEdit自动获得Focus。
另外只有Label才可以有Buddy
Layout之间可以相互嵌套,Vlayout->addLayout(hLayout);
但是注意FormLayout没有addLayout,只有addChildLayout,并且addChildLayout的访问权限还是protected。
相关文章推荐
- Qt串口为什么会丢消息包?
- qxt: 并不支持qt5,其他excel解析的情况
- Qt中文支持和文件读写
- Qt中QStack简单应用
- Qt中子窗体控件向父窗体控件传值
- 关于QT的系统总结
- qt图像类
- [转] Qt 多线程学习
- SPOJ QTREE5 lct
- 弄懂Qt2维坐标系
- qt学习笔记(九)之数据库_初窥用户接口层
- 转载:pyqt的signal和solit
- qt学习笔记(七)之数据库简介
- qt学习笔记(六)之简析对象树
- qt学习笔记(五)之浅析信号与槽进制
- qt学习笔记(四)之对话框-Qt内建对话框
- qt学习笔记(三)之对话框-QDialog
- qt学习笔记(二)之布局管理器&信号与槽(简介)
- qt学习笔记(一)之Hello world
- 隐式共享:qt