#include "basetableview.h"
#include <QScrollBar>
#include <QFontDatabase>
#include <QHeaderView>
#include <QSortFilterProxyModel>
BaseTableView::BaseTableView(QWidget *parent) :
QWidget(parent)
{
tableTitle=nullptr;
initWindow();
connect(tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(onTableClicked(QModelIndex)));
//connect(tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onTableDoubleClicked(QModelIndex)));
m_searchFilter = "";
}
BaseTableView::~BaseTableView()
{
m_service.clear();
m_model.clear();
if(tableTitle!=nullptr)
{
delete tableTitle;
tableTitle=nullptr;
}
}
void BaseTableView::initWindow()
{
if (this->objectName().isEmpty())
{
this->setObjectName(QString::fromUtf8("BaseTableView"));
}
this->resize(400, 300);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
this->setSizePolicy(sizePolicy);
verticalLayout = new QVBoxLayout(this);
verticalLayout->setSpacing(0);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
verticalLayout->setContentsMargins(0, 0, 0, 0);
toolbarLayout = new QVBoxLayout();
toolbarLayout->setMargin(0);
toolbarLayout->setObjectName(QString::fromUtf8("toolbarLayout"));
verticalLayout->addLayout(toolbarLayout);
tableTitle=new QLabel(this);
tableTitle->setText(tr("表格抬头"));
/*QFont font = tableTitle->font();
font.setPointSize(AppRunTime::instance()->getDynamicValueX(24));
font.setBold(false);
font.setFamily("SourceHanSansCn-Regular");
tableTitle->setFont(font);
tableTitle->setStyleSheet("color: #272745;");
*/
QHBoxLayout *tableLableLayout = new QHBoxLayout;
tableLableLayout->setMargin(0);
tableLableLayout->addStretch();
tableLableLayout->addWidget(tableTitle);
tableLableLayout->addStretch();
tableTitle->setVisible(false);
verticalLayout->addLayout(tableLableLayout);
verticalLayout_2 = new QVBoxLayout;
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
verticalLayout_2->setContentsMargins(12, 12, 12, 12);
tableView = new QTableView(this);
tableView->setObjectName(QString::fromUtf8("tableView"));
verticalLayout_2->addWidget(tableView);
verticalLayout->addLayout(verticalLayout_2);
pageControllerLayout = new QVBoxLayout();
pageControllerLayout->setObjectName(QString::fromUtf8("pageControllerLayout"));
pageControllerLayout->setContentsMargins(-1, 0, -1, -1);
verticalLayout->addLayout(pageControllerLayout);
//this->setWindowTitle(QApplication::translate("BaseTableView", "Form", nullptr));
QMetaObject::connectSlotsByName(this);
}
void BaseTableView::initView(bool showToolbar, bool showPageController)
{
showToolbar=true;showPageController=true;
initTable();
}
void BaseTableView::setSelectedRow(int row)
{
tableView->selectRow(row);
}
void BaseTableView::setTableNoSelection()
{
tableView->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
}
void BaseTableView::setTableMutiSelection()
{
tableView->setSelectionMode(QAbstractItemView::SelectionMode::MultiSelection);
}
void BaseTableView::onSearchFilterChanged(QString searchFilter)
{
m_searchFilter = searchFilter;
}
void BaseTableView::initTable()
{
// 设置单选
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
// 设置整行选中
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
// 设置纵向拉伸(文字过长换行时拉伸行高)
// ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// 设置行颜色交错(白灰交错)
tableView->setAlternatingRowColors(true);
// 设置横向拉伸(文字较长时拉伸单元格宽度)
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// 设置最后一列拉伸
tableView->horizontalHeader()->setStretchLastSection(true);
// 设置表头字体为中等
/*QFont font;
font.setWeight(AppRunTime::instance()->getDynamicValueX(63));
tableView->horizontalHeader()->setFont(font);
// 设置表头字体大小、去除边框、设置背景色
int headerFontSize = AppRunTime::instance()->getDynamicValueX(14);
tableView->horizontalHeader()->setStyleSheet(QString(
"QHeaderView::section{border: 0px solid white; background-color:#ececec; font-size:%1px}").arg(headerFontSize));
// 设置最后一行拉伸
// ui->tableView->verticalHeader()->setStretchLastSection(true);
// 设置固定行高
tableView->verticalHeader()->setDefaultSectionSize(AppRunTime::instance()->getDynamicValueX(45));
// 隐藏列号
tableView->verticalHeader()->hide();
// 去除表格边框
tableView->setShowGrid(false);
// 设置表格字体大小
int contentFontSize = AppRunTime::instance()->getDynamicValueX(13);
tableView->setStyleSheet(QString("font-size:%1px;").arg(contentFontSize));
// 设置表格数据模型,增加排序模型
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(m_model.data());
tableView->setModel(proxyModel);*/
// 设置滚动条宽度
tableView->verticalScrollBar()->setStyleSheet("width:24px; border:1px solid #cccccc;");
tableView->horizontalScrollBar()->setStyleSheet("height:24px; border:1px solid #ececec;");
// 设置允许点击表头进行排序
tableView->setSortingEnabled(true);
}
没有合适的资源?快使用搜索试试~ 我知道了~
Qt MVC模型视图代码标准模板
共82个文件
o:31个
cpp:26个
h:14个
需积分: 6 5 下载量 181 浏览量
2022-11-24
13:53:46
上传
评论
收藏 6.89MB ZIP 举报
温馨提示
Qt MVC模型视图代码标准模板
资源推荐
资源详情
资源评论
收起资源包目录
modelView-sqlite.zip (82个子文件)
modelView-sqlite
bin
debug
my.db 16KB
config
systemFlag.ini 18B
sqliteTest 3.75MB
sqliteTest
sqlitetest.cpp 123B
base
basetablemodel.h 3KB
basedataservice.cpp 103B
basetableview.h 3KB
basetableview.cpp 6KB
basedataservice.h 1KB
basetablemodel.cpp 2KB
sqlitetest.h 204B
sqliteTest.pro 2KB
global
inifile.h 1KB
inifile.cpp 3KB
apprun.cpp 3KB
yc_score.cpp 554B
apprun.h 477B
yc_score.h 491B
scoreview
scoreservice.cpp 429B
scoremodel.h 423B
sorcewidget.h 299B
scoretable.h 214B
scorewidget.cpp 5KB
scoretable.cpp 55B
scorewidget.h 484B
sorcewidget.cpp 91B
scoreservice.h 252B
scoremodel.cpp 2KB
main.cpp 250B
modelView-sqlite.pro 49B
modelView-sqlite.pro.user 23KB
Debug
sqliteTest
moc_yc_score.cpp 3KB
moc_yc_score.o 499KB
moc_basedateservice.cpp 3KB
moc_basedateservice.o 530KB
moc_scoremodel.o 607KB
moc_basetablemodel.cpp 3KB
basedateservice.o 438KB
sqliteTest 1.74MB
scoreservice.o 524KB
.qmake.stash 739B
moc_predefs.h 13KB
basetablemodel.o 702KB
moc_basetablemodel.o 642KB
debug
moc_yc_score.cpp 3KB
moc_yc_score.o 499KB
moc_scorewidget.cpp 3KB
moc_basedataservice.o 530KB
moc_basedateservice.cpp 3KB
moc_basedateservice.o 530KB
moc_scoremodel.o 607KB
moc_basetablemodel.cpp 3KB
moc_basetableview.cpp 5KB
scoretable.o 502KB
moc_scorewidget.o 821KB
basetableview.o 908KB
basedateservice.o 438KB
scoreservice.o 539KB
moc_inifile.cpp 3KB
apprun.o 765KB
moc_predefs.h 13KB
moc_scoretable.o 533KB
basetablemodel.o 702KB
moc_basetablemodel.o 642KB
scorewidget.o 926KB
yc_score.o 450KB
moc_scoremodel.cpp 3KB
moc_basetableview.o 864KB
main.o 931KB
moc_scoretable.cpp 3KB
scoremodel.o 663KB
basedataservice.o 438KB
inifile.o 524KB
moc_inifile.o 502KB
moc_basedataservice.cpp 3KB
yc_score.o 441KB
Makefile 174KB
moc_scoremodel.cpp 3KB
main.o 455KB
scoremodel.o 646KB
.qmake.stash 739B
Makefile 46KB
共 82 条
- 1
资源评论
只是个~小不点
- 粉丝: 1w+
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功