QLabel y QPushButton se alinean
Me cuesta alinear varios widgets qt (etiqueta y botón). Quiero que los widgets (de color verde y rojo respectivamente) se alineen. ¿Algún consejo?
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QVBoxLayout * const layout = new QVBoxLayout(ui->scrollAreaWidgetContents);
for(int i=0; i!=100; ++i)
{
QLabel *label = new QLabel();
layout->addWidget(label);
label->setText(QString::number(i));
label->setStyleSheet("background-color: red");
label->setFixedWidth(100);
QPushButton *pushButton = new QPushButton();
layout ->addWidget(pushButton);
int menu_x_pos = label->pos().x();
int menu_y_pos = label->pos().y();
pushButton->setGeometry(menu_x_pos+120, menu_y_pos,10,20);
pushButton->setText(QString::number(i));
pushButton->setStyleSheet("background-color: green");
}
}
Dialog::~Dialog()
{
delete ui;
}