-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavegameview.cpp
48 lines (42 loc) · 1.7 KB
/
savegameview.cpp
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
#include "savegameview.h"
#include "ui_savegameview.h"
SaveGameDialog::SaveGameDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SaveGameDialog)
{
ui->setupUi(this);
ui->gameFileTable->setColumnCount(2);
ui->gameFileTable->setHorizontalHeaderLabels(QStringList() << "File Name" << "Update Time");
ui->gameFileTable->setRowCount(3);
ui->gameFileTable->setItem(0, 0, new QTableWidgetItem("111"));
ui->gameFileTable->setItem(1, 0, new QTableWidgetItem("222"));
ui->gameFileTable->setItem(2, 0, new QTableWidgetItem("333"));
// select by rows
ui->gameFileTable->setSelectionBehavior(QTableWidget::SelectRows);
// cannot select multiple rows
ui->gameFileTable->setSelectionMode(QTableWidget::SingleSelection);
// cannot edit the cells of the table
ui->gameFileTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->gameFileTable->setHorizontalHeaderLabels(QStringList() << "File Name" << "Create Time");
ui->deleteBtn->setEnabled(false);
connect(ui->gameFileTable, &QTableWidget::cellClicked, this, [=]() {
ui->deleteBtn->setEnabled(true);
});
connect(ui->addBtn, &QPushButton::clicked, this, [=]() {
if (ui->gameFileTable->currentRow() == -1)
ui->gameFileTable->insertRow(ui->gameFileTable->rowCount());
else
ui->gameFileTable->insertRow(ui->gameFileTable->currentRow() + 1);
});
connect(ui->deleteBtn, &QPushButton::clicked, this, [=]() {
ui->gameFileTable->removeRow(ui->gameFileTable->currentRow());
});
}
void SaveGameDialog::resizeEvent(QResizeEvent *)
{
ui->gameFileTable->setColumnWidth(0, this->width()*0.5);
}
SaveGameDialog::~SaveGameDialog()
{
delete ui;
}