-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowcomment.cpp
48 lines (42 loc) · 1.56 KB
/
showcomment.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 "showcomment.h"
#include "ui_showcomment.h"
#include <QTableView>
ShowComment::ShowComment(QWidget *parent) :
QWidget(parent),
ui(new Ui::ShowComment)
{
ui->setupUi(this);
this->model = new QSqlQueryModel(ui->tableShowComment);
this->initTableShowComment();
connect(ui->btnCloseComment, SIGNAL(clicked()), this, SLOT(onBtnCloseClicked()));
}
ShowComment::~ShowComment()
{
delete ui;
delete model;
}
void ShowComment::initTableShowComment()
{
this->model->setQuery("SELECT USERNAME,COMMENT, SOLDDATE FROM COMMENTINFO");
model->setHeaderData(0,Qt::Horizontal,tr("UserName"));
model->setHeaderData(1, Qt::Horizontal, tr("CommentDetails"));
model->setHeaderData(2, Qt::Horizontal, tr("CommetDate"));
ui->tableShowComment->setModel(model);
// 设置默认行高
ui->tableShowComment->verticalHeader()->setDefaultSectionSize(50);
ui->tableShowComment->setColumnWidth(0, 130);
ui->tableShowComment->setColumnWidth(1, 500);
ui->tableShowComment->setColumnWidth(2, 160);
//设置列宽不可变动,即不能通过鼠标拖动增加列宽
ui->tableShowComment->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// 设置隔行变色
ui->tableShowComment->setAlternatingRowColors(true);
// 设置文字居中
// 设置自适应列宽
//ui->tableShowComment->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableShowComment->setSelectionBehavior(QAbstractItemView::SelectRows); // 选中时整行选中
}
void ShowComment::onBtnCloseClicked()
{
exit(0);
}