blob: b7e5db59683a859ea3048b08ae06f2ffcc9e4b78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "Record.hpp"
#include "qabstractitemview.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QMainWindow>
#include <QPushButton>
#include <QTableView>
#include <QVBoxLayout>
#include <QWidget>
int main(int argc, char *argv[]) {
QApplication application(argc, argv);
QWidget window;
QVBoxLayout window_layout;
window.setLayout(&window_layout);
QHBoxLayout top_bar;
window_layout.addLayout(&top_bar);
QPushButton import_button(QStringLiteral("导入"));
QPushButton export_button(QStringLiteral("导出"));
QPushButton add_book_button(QStringLiteral("添加书"));
top_bar.addWidget(&import_button);
top_bar.addWidget(&export_button);
top_bar.addStretch(1);
top_bar.addWidget(&add_book_button);
QHBoxLayout center_area;
window_layout.addLayout(¢er_area);
QTableView book_view;
book_view.verticalHeader()->hide();
book_view.setSelectionBehavior(QAbstractItemView::SelectRows);
book_view.setEditTriggers(QAbstractItemView::DoubleClicked);
book_view.setSelectionMode(QAbstractItemView::SingleSelection);
QTableView vendor_view;
center_area.addWidget(&book_view);
center_area.addWidget(&vendor_view);
Record record;
BookModel book_model(&record);
book_view.setModel(&book_model);
QObject::connect(&add_book_button, &QPushButton::clicked, [&book_model]() {
book_model.insertRow(book_model.rowCount());
});
window.show();
return application.exec();
}
|