2024-09-12 16:23:44 +08:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCursor>
|
|
|
|
|
|
|
|
|
|
#include "globalparameters.h"
|
|
|
|
|
#include "mytablemodel.h"
|
|
|
|
|
|
|
|
|
|
AppData::~AppData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppData::AppData(token)
|
|
|
|
|
{
|
|
|
|
|
lstDataTableHeaderText << ("Status")
|
|
|
|
|
<< ("Parameter")
|
|
|
|
|
<< ("Value")
|
|
|
|
|
<< ("Unit")
|
|
|
|
|
<< ("Time");
|
|
|
|
|
|
|
|
|
|
nTimeOut = 5000;
|
|
|
|
|
qsDestinationIp = "127.0.0.1";
|
|
|
|
|
|
|
|
|
|
qsLastErrorString = "OK";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppCommon::AppCommon(token)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppCommon::~AppCommon()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppCommon::InitializeTableView(MyTableModel *model, QTableView *tableView)
|
|
|
|
|
{
|
|
|
|
|
//设置tableview的model
|
|
|
|
|
model->setHeadData(AppData::getInstance()->lstDataTableHeaderText);
|
|
|
|
|
tableView->setModel(model);
|
|
|
|
|
|
|
|
|
|
//tableView->horizontalHeader()->setStyleSheet("QHeaderView::section {color: black;padding-left: 4px;border: 1px solid #6c6c6c;}");
|
|
|
|
|
tableView->horizontalHeader()->setStyleSheet("QHeaderView::section{background:lightgray;}");
|
|
|
|
|
//tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); //Stretch
|
|
|
|
|
|
|
|
|
|
//点击表时不对表头行光亮(获取焦点)
|
|
|
|
|
tableView->horizontalHeader()->setHighlightSections(false);
|
|
|
|
|
|
|
|
|
|
tableView->horizontalHeader()->setDefaultSectionSize(35);
|
|
|
|
|
tableView->verticalHeader()->setDefaultSectionSize(30); //行高
|
|
|
|
|
|
|
|
|
|
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
|
|
tableView->setAlternatingRowColors(true);
|
|
|
|
|
tableView->setTextElideMode(Qt::ElideMiddle);
|
|
|
|
|
|
2024-09-13 12:53:02 +08:00
|
|
|
|
//tableView->horizontalHeader()->setVisible(true);
|
|
|
|
|
//tableView->horizontalHeader()->setFixedHeight(40);
|
|
|
|
|
|
2024-09-12 16:23:44 +08:00
|
|
|
|
// //设置表头字体加粗
|
|
|
|
|
// QFont font = tableView->horizontalHeader()->font();
|
|
|
|
|
// font.setBold(true);
|
|
|
|
|
// tableView->horizontalHeader()->setFont(font);
|
|
|
|
|
|
|
|
|
|
//设置表头字体
|
|
|
|
|
tableView->horizontalHeader()->setFont(QFont("Arial", 12));
|
|
|
|
|
//所有单元格的字体 设置成一样
|
|
|
|
|
tableView->setFont(QFont("Arial", 9));
|
|
|
|
|
|
|
|
|
|
//设置表格数据区内的所有单元格都不允许编辑
|
|
|
|
|
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
2024-09-13 12:53:02 +08:00
|
|
|
|
#if 0
|
2024-09-12 16:23:44 +08:00
|
|
|
|
//设置列宽
|
|
|
|
|
int w = tableView->width();
|
|
|
|
|
int base = w /(AppData::getInstance()->lstDataTableHeaderText.count()-1);
|
|
|
|
|
tableView->setColumnWidth(0,base-45);
|
|
|
|
|
tableView->setColumnWidth(1,base-20);
|
|
|
|
|
tableView->setColumnWidth(2,base+30);
|
|
|
|
|
tableView->setColumnWidth(3,base+10);
|
|
|
|
|
tableView->setColumnWidth(4,base);
|
2024-09-13 12:53:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 设置QTableView的列宽度根据总宽度平均分配
|
|
|
|
|
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
//tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
|
2024-09-12 16:23:44 +08:00
|
|
|
|
|
|
|
|
|
tableView->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CWaitorCursor::CWaitorCursor()
|
|
|
|
|
{
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CWaitorCursor::~CWaitorCursor()
|
|
|
|
|
{
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|