I have discovered Qt recently and I search to make a form like this :
And I succeeded with this code :
#include <QApplication>
#include <QtWidgets>
int main (int argc, char *argv[])
{
QApplication myApp(argc,argv);
QWidget myWindow;
// Create Main Box (Vertical) and Line Box (Horizontal)
QVBoxLayout *mainBox = new QVBoxLayout;
QHBoxLayout *lineBox = new QHBoxLayout;
//-------- Box For Name --------//
QVBoxLayout *nameBox = new QVBoxLayout;
QLabel *nameLabel = new QLabel("Name");
QLineEdit *nameInput = new QLineEdit();
nameBox->addWidget(nameLabel);
nameBox->addWidget(nameInput);
//------------------------------//
//------ Box For LastName ------//
QVBoxLayout *lastNameBox = new QVBoxLayout;
QLabel *lastNameLabel = new QLabel("Last Name");
QLineEdit *lastNameInput = new QLineEdit();
lastNameBox->addWidget(lastNameLabel);
lastNameBox->addWidget(lastNameInput);
//------------------------------//
// Add Box to Line
lineBox->addLayout(nameBox);
lineBox->addLayout(lastNameBox);
// Add Line to Main Box
mainBox->addLayout(lineBox);
// Finalize and Show Window
myWindow.setLayout(mainBox);
myWindow.setWindowTitle("Example");
myWindow.show();
return myApp.exec();
}
But there is not simpler solution than that...? It's not possible to use QFormLayout to put label and Qline one below the other...? A vertical alignment...?