15.横向布局

  • 头文件
    1 #include <QHBoxLayout>
    2 #include <QPushButton>
    3 #include <QVBoxLayout>
    4 #include <QLineEdit>
    5 #include <QLabel>
  • mainwindow.cpp
     1 #include "mainwindow.h"
     2 #include "ui_mainwindow.h"
     3 
     4 MainWindow::MainWindow(QWidget *parent) :
     5     QMainWindow(parent),
     6     ui(new Ui::MainWindow)
     7 {
     8     ui->setupUi(this);
     9 
    10     pplabel = new QLabel *[10];
    11     for(int i=0;i<10;i++)
    12     {
    13         QString str;
    14         str.sprintf("_%d",i);
    15         pplabel[i] = new QLabel(str);
    16     }
    17 
    18 
    19 
    20     hl = new QHBoxLayout(this);
    21     hl->setMargin(10);
    22     for(int i=0;i<10;i++)
    23     {
    24         hl->addWidget(pplabel[i]);
    25     }
    26 
    27 
    28 }
    29 
    30 MainWindow::~MainWindow()
    31 {
    32     delete ui;
    33 }
原文地址:https://www.cnblogs.com/xiaochi/p/8746786.html