title: QLabel and QPushButton align
body: <p>I'm having a hard time aligning multiple qt widgets (label and push button). I want the widgets (colored green and red respectively) to line up. Any advice? </p>
  
  <pre><code>#include &lt;QVBoxLayout&gt;
  #include &lt;QLabel&gt;
  #include &lt;QPushButton&gt;
  #include "ui_dialog.h"
  
  Dialog::Dialog(QWidget *parent)
  : QDialog(parent),
  ui(new Ui::Dialog)
  {
  ui-&gt;setupUi(this);
  QVBoxLayout * const layout = new QVBoxLayout(ui-&gt;scrollAreaWidgetContents);
  for(int i=0; i!=100; ++i)
  {
    QLabel *label = new QLabel();
    layout-&gt;addWidget(label);
    label-&gt;setText(QString::number(i));
    label-&gt;setStyleSheet("background-color: red");
    label-&gt;setFixedWidth(100);
    QPushButton *pushButton = new QPushButton();
    layout -&gt;addWidget(pushButton);
    int menu_x_pos = label-&gt;pos().x();
    int menu_y_pos = label-&gt;pos().y();
    pushButton-&gt;setGeometry(menu_x_pos+120, menu_y_pos,10,20);
    pushButton-&gt;setText(QString::number(i));
    pushButton-&gt;setStyleSheet("background-color: green");
    }
    }
    Dialog::~Dialog()
  {
    delete ui;
   }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Jgh3O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jgh3O.png" alt=""></a></p>