|
|
@ -1,4 +1,4 @@
|
|
|
|
#include "CUIMultiTableWidget.h"
|
|
|
|
#include "CUIMultiTableWidget.h"
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QTableWidgetItem>
|
|
|
|
#include <QTableWidgetItem>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QHeaderView>
|
|
|
@ -16,8 +16,8 @@ CUIMultiTableWidget::CUIMultiTableWidget(CUIConfig* conf, QVector<CUI*> &subCUI,
|
|
|
|
void CUIMultiTableWidget::initUI()
|
|
|
|
void CUIMultiTableWidget::initUI()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QStringList headers;
|
|
|
|
QStringList headers;
|
|
|
|
headers<<tr("index")<<tr("name")<<tr("view");
|
|
|
|
headers << tr("index") << tr("name") << tr("alias") << tr("view");
|
|
|
|
QList<QList<QString>> items;
|
|
|
|
QList<QList<QString >> items;
|
|
|
|
QList<QString> item1 = {tr("quaility"), "quaility"};
|
|
|
|
QList<QString> item1 = {tr("quaility"), "quaility"};
|
|
|
|
QList<QString> item2 = {tr("x"), "x"};
|
|
|
|
QList<QString> item2 = {tr("x"), "x"};
|
|
|
|
QList<QString> item3 = {tr("y"), "y"};
|
|
|
|
QList<QString> item3 = {tr("y"), "y"};
|
|
|
@ -28,7 +28,7 @@ void CUIMultiTableWidget::initUI()
|
|
|
|
items.append(item4);
|
|
|
|
items.append(item4);
|
|
|
|
// 根据配置来初始化tableWidget
|
|
|
|
// 根据配置来初始化tableWidget
|
|
|
|
m_tableWidget = new QTableWidget(this);
|
|
|
|
m_tableWidget = new QTableWidget(this);
|
|
|
|
m_tableWidget->setColumnCount(items.count() + 2);
|
|
|
|
m_tableWidget->setColumnCount(items[0].count() + 2);
|
|
|
|
m_tableWidget->setRowCount(items.count());
|
|
|
|
m_tableWidget->setRowCount(items.count());
|
|
|
|
m_tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
m_tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
// 设置水平表头的背景颜色
|
|
|
|
// 设置水平表头的背景颜色
|
|
|
@ -38,29 +38,27 @@ void CUIMultiTableWidget::initUI()
|
|
|
|
// 隐藏垂直表头
|
|
|
|
// 隐藏垂直表头
|
|
|
|
QHeaderView *verticalHeader = m_tableWidget->verticalHeader();
|
|
|
|
QHeaderView *verticalHeader = m_tableWidget->verticalHeader();
|
|
|
|
verticalHeader->setVisible(false);
|
|
|
|
verticalHeader->setVisible(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < items.count(); i++) {
|
|
|
|
for (int i=0;i<items.count();i++) {
|
|
|
|
|
|
|
|
QList<QString> item = items[i];
|
|
|
|
QList<QString> item = items[i];
|
|
|
|
// 序号
|
|
|
|
// 序号
|
|
|
|
QTableWidgetItem* indexItem = new QTableWidgetItem(QString("%1").arg(i+1));
|
|
|
|
QTableWidgetItem* indexItem = new QTableWidgetItem(QString("%1").arg(i + 1));
|
|
|
|
indexItem->setFlags(indexItem->flags() &~Qt::ItemIsSelectable);
|
|
|
|
indexItem->setFlags(indexItem->flags() & ~Qt::ItemIsSelectable);
|
|
|
|
indexItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中
|
|
|
|
indexItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中
|
|
|
|
m_tableWidget->setItem(i,0, indexItem);
|
|
|
|
m_tableWidget->setItem(i, 0, indexItem);
|
|
|
|
// 内容
|
|
|
|
// 内容
|
|
|
|
for (int j=0;j<item.count();j++) {
|
|
|
|
for (int j = 0; j < item.count(); j++) {
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(item[j]);
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(item[j]);
|
|
|
|
nameItem->setFlags(indexItem->flags() &~Qt::ItemIsSelectable);
|
|
|
|
nameItem->setFlags(indexItem->flags() & ~Qt::ItemIsSelectable);
|
|
|
|
nameItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中
|
|
|
|
nameItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中
|
|
|
|
m_tableWidget->setItem(i,j+1, nameItem);
|
|
|
|
m_tableWidget->setItem(i, j + 1, nameItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 复选框
|
|
|
|
// 复选框
|
|
|
|
QTableWidgetItem *checkBoxItem = new QTableWidgetItem();
|
|
|
|
QTableWidgetItem *checkBoxItem = new QTableWidgetItem();
|
|
|
|
m_tableWidget->setItem(i,item.count() + 1, checkBoxItem);
|
|
|
|
m_tableWidget->setItem(i, item.count() + 1, checkBoxItem);
|
|
|
|
QCheckBox* checkBox = new QCheckBox();
|
|
|
|
QCheckBox* checkBox = new QCheckBox();
|
|
|
|
checkBox->setStyleSheet("margin-left:45%; margin-right:45%;");// 设置水平居中
|
|
|
|
checkBox->setStyleSheet("margin-left:45%; margin-right:45%;");// 设置水平居中
|
|
|
|
m_tableWidget->setCellWidget(i, item.count() + 1, checkBox);
|
|
|
|
m_tableWidget->setCellWidget(i, item.count() + 1, checkBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_layout = new QVBoxLayout;
|
|
|
|
m_layout = new QVBoxLayout;
|
|
|
|
m_layout->addWidget(m_tableWidget);
|
|
|
|
m_layout->addWidget(m_tableWidget);
|
|
|
|
this->setLayout(m_layout);
|
|
|
|
this->setLayout(m_layout);
|
|
|
|