- #include <QtGui>
-
-
int main(int argc, char *argv[])
-
{
-
QApplication app(argc, argv);
-
QWidget window;
-
-
QLabel *queryLabel = new QLabel(
-
QApplication::translate("nestedlayouts", "Query:"));
-
QLineEdit *queryEdit = new QLineEdit();
-
QTableView *resultView = new QTableView();
-
-
QHBoxLayout *queryLayout = new QHBoxLayout();
-
queryLayout->addWidget(queryLabel);
-
queryLayout->addWidget(queryEdit);
-
-
QVBoxLayout *mainLayout = new QVBoxLayout();
-
mainLayout->addLayout(queryLayout);
-
mainLayout->addWidget(resultView);
-
window.setLayout(mainLayout);
-
-
// Set up the model and configure the view...
-
QStandardItemModel model;
-
QStringList qstringlist;
-
qstringlist << "Name" << "Number";
-
-
model.setHorizontalHeaderLabels (qstringlist);
-
// model.setHorizontalHeaderLabels(
-
// QStringList() << QApplication::translate("nestedlayouts", "Name")
-
// << QApplication::translate("nestedlayouts", "Office"));
-
-
QList<QStringList> rows = QList<QStringList>()
-
<< (QStringList() << "Verne Nilsen" << "123")
-
<< (QStringList() << "Carlos Tang" << "77")
-
<< (QStringList() << "Bronwyn Hawcroft" << "119")
-
<< (QStringList() << "Alessandro Hanssen" << "32")
-
<< (QStringList() << "Andrew John Bakken" << "54")
-
<< (QStringList() << "Vanessa Weatherley" << "85")
-
<< (QStringList() << "Rebecca Dickens" << "17")
-
<< (QStringList() << "David Bradley" << "42")
-
<< (QStringList() << "Knut Walters" << "25")
-
<< (QStringList() << "Andrea Jones" << "34");
-
-
foreach (QStringList row, rows) {
-
QList<QStandardItem *> items;
-
foreach (QString text, row)
-
items.append(new QStandardItem(text));
-
model.appendRow(items);
-
}
-
-
resultView->setModel(&model);
-
resultView->verticalHeader()->hide();
-
resultView->horizontalHeader()->setStretchLastSection(true);
-
-
-
window.setWindowTitle(
-
QApplication::translate("nestedlayouts", "Nested layouts"));
-
window.show();
-
return app.exec();
- }
- /*
- QT学习的第一天, 代码都是QT助手上的。
- 在这里学到一个东西,匿名类对象,如 : QStringList() << "Verne Nilsen" << "123"
- 这里的foreach, 是QT中特有的一个C++方法,类似于C#中的foreach,具体使用,查看QT助手,这个助手很强大的说
- */