我最近发现了 Qt,我搜索制作这样的表格:
我成功使用了这段代码:
#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();
}
但是没有比这更简单的解决方案了......?不可能使用 QFormLayout 将标签和 Qline 放在另一个下方...?垂直对齐...?