介绍

VFlowLayout 基于 QFlowLayout, QFlowLayout QT本身并没有集成,而是作为单独的例子使用。因为有时候工程会有流动布局的需要,故加入到 VLibs中。为了保证库名的一致性,做了改名集成,源代码在QT的例子中可以找到,或者访问开源地址:https://github.com/XwAdmin/QFlowlayout (我上传的)。
如果你使用了 VFlowLayout (QFlowLayout),你应该感谢QT的劳作。而不是我。

操作

使用方法和QHBoxLayout,QVBoxLayout一致。

  1. #include <VFlowLayout.h>

▼ QT 官方例子

  1. #include <QFlowLayout.h>
  2. QFlowLayout *flowLayout = new QFlowLayout(this);
  3. flowLayout->addWidget(new QPushButton(tr("Short")));
  4. flowLayout->addWidget(new QPushButton(tr("Longer")));
  5. flowLayout->addWidget(new QPushButton(tr("Different text")));
  6. flowLayout->addWidget(new QPushButton(tr("More text")));
  7. flowLayout->addWidget(new QLineEdit(tr("More text")));
  8. flowLayout->addWidget(new QPushButton(tr("Even longer button text")));
  9. this->setLayout(flowLayout);

▼ VLibs 实例

  1. #include <VFlowLayout.h>
  2. QWidget *widget = new QWidget;
  3. widget->setWindowTitle("调整大小试试看");
  4. widget->setAttribute(Qt::WA_DeleteOnClose);
  5. VFlowLayout* flow = new VFlowLayout;
  6. for ( int n = 0; 20 > n; ++n )
  7. flow->addWidget( new QPushButton(QString::number(n), widget));
  8. widget->setLayout(flow);
  9. widget->show();

▼ VLibs 展示
浮动布局.gif