介绍
VFlowLayout 基于 QFlowLayout, QFlowLayout QT本身并没有集成,而是作为单独的例子使用。因为有时候工程会有流动布局的需要,故加入到 VLibs中。为了保证库名的一致性,做了改名集成,源代码在QT的例子中可以找到,或者访问开源地址:https://github.com/XwAdmin/QFlowlayout (我上传的)。
如果你使用了 VFlowLayout (QFlowLayout),你应该感谢QT的劳作。而不是我。
操作
使用方法和QHBoxLayout,QVBoxLayout一致。
#include <VFlowLayout.h>
▼ QT 官方例子
#include <QFlowLayout.h>
QFlowLayout *flowLayout = new QFlowLayout(this);
flowLayout->addWidget(new QPushButton(tr("Short")));
flowLayout->addWidget(new QPushButton(tr("Longer")));
flowLayout->addWidget(new QPushButton(tr("Different text")));
flowLayout->addWidget(new QPushButton(tr("More text")));
flowLayout->addWidget(new QLineEdit(tr("More text")));
flowLayout->addWidget(new QPushButton(tr("Even longer button text")));
this->setLayout(flowLayout);
▼ VLibs 实例
#include <VFlowLayout.h>
QWidget *widget = new QWidget;
widget->setWindowTitle("调整大小试试看");
widget->setAttribute(Qt::WA_DeleteOnClose);
VFlowLayout* flow = new VFlowLayout;
for ( int n = 0; 20 > n; ++n )
flow->addWidget( new QPushButton(QString::number(n), widget));
widget->setLayout(flow);
widget->show();
▼ VLibs 展示