Chinaunix首页 | 论坛 | 博客
  • 博客访问: 303616
  • 博文数量: 73
  • 博客积分: 1850
  • 博客等级: 上尉
  • 技术积分: 757
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-18 16:12
文章分类

全部博文(73)

文章存档

2011年(8)

2010年(26)

2009年(39)

分类: C/C++

2010-12-29 23:50:24

  1. #include <QtGui>

  2. int main(int argc, char *argv[])
  3. {
  4.     QApplication app(argc, argv);
  5.     QWidget window;

  6.     QLabel *queryLabel = new QLabel(
  7.             QApplication::translate("nestedlayouts", "Query:"));
  8.     QLineEdit *queryEdit = new QLineEdit();
  9.     QTableView *resultView = new QTableView();

  10.     QHBoxLayout *queryLayout = new QHBoxLayout();
  11.     queryLayout->addWidget(queryLabel);
  12.     queryLayout->addWidget(queryEdit);

  13.     QVBoxLayout *mainLayout = new QVBoxLayout();
  14.     mainLayout->addLayout(queryLayout);
  15.     mainLayout->addWidget(resultView);
  16.     window.setLayout(mainLayout);

  17.     // Set up the model and configure the view...
  18.     QStandardItemModel model;
  19.     QStringList qstringlist;
  20.     qstringlist << "Name" << "Number";

  21.     model.setHorizontalHeaderLabels (qstringlist);
  22.     // model.setHorizontalHeaderLabels(
  23.      // QStringList() << QApplication::translate("nestedlayouts", "Name")
  24.       // << QApplication::translate("nestedlayouts", "Office"));

  25.          QList<QStringList> rows = QList<QStringList>()
  26.              << (QStringList() << "Verne Nilsen" << "123")
  27.              << (QStringList() << "Carlos Tang" << "77")
  28.              << (QStringList() << "Bronwyn Hawcroft" << "119")
  29.              << (QStringList() << "Alessandro Hanssen" << "32")
  30.              << (QStringList() << "Andrew John Bakken" << "54")
  31.              << (QStringList() << "Vanessa Weatherley" << "85")
  32.              << (QStringList() << "Rebecca Dickens" << "17")
  33.              << (QStringList() << "David Bradley" << "42")
  34.              << (QStringList() << "Knut Walters" << "25")
  35.              << (QStringList() << "Andrea Jones" << "34");

  36.          foreach (QStringList row, rows) {
  37.              QList<QStandardItem *> items;
  38.              foreach (QString text, row)
  39.                  items.append(new QStandardItem(text));
  40.              model.appendRow(items);
  41.          }

  42.          resultView->setModel(&model);
  43.          resultView->verticalHeader()->hide();
  44.          resultView->horizontalHeader()->setStretchLastSection(true);


  45.     window.setWindowTitle(
  46.             QApplication::translate("nestedlayouts", "Nested layouts"));
  47.     window.show();
  48.     return app.exec();
  49. }
  50. /*
  51. QT学习的第一天, 代码都是QT助手上的。
  52. 在这里学到一个东西,匿名类对象,如 : QStringList() << "Verne Nilsen" << "123"
  53. 这里的foreach, 是QT中特有的一个C++方法,类似于C#中的foreach,具体使用,查看QT助手,这个助手很强大的说
  54. */
阅读(2281) | 评论(0) | 转发(0) |
0

上一篇:升级了cublog..

下一篇:QT 2, Address Book

给主人留下些什么吧!~~