feat:完成告警列表中操作按钮的绘制
This commit is contained in:
parent
9d2a6cc2cb
commit
3828bd6f9c
|
|
@ -132,9 +132,26 @@ public:
|
||||||
~AlarmEventDataDelegate();
|
~AlarmEventDataDelegate();
|
||||||
|
|
||||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ControlButton
|
||||||
|
{
|
||||||
|
QRect rect;
|
||||||
|
QColor normalBgColor;
|
||||||
|
QColor hoverBgColor;
|
||||||
|
QColor pressedBgColor;
|
||||||
|
QColor borderColor;
|
||||||
|
QColor textColor;
|
||||||
|
QFont textFont;
|
||||||
|
int borderWidth;
|
||||||
|
int borderRaius;
|
||||||
|
QString text;
|
||||||
|
};
|
||||||
|
|
||||||
QTableView* m_tableView;
|
QTableView* m_tableView;
|
||||||
|
ControlButton m_btnConfirm;
|
||||||
|
ControlButton m_btnReplay;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
///////------AlarmEventDataFilter-----
|
///////------AlarmEventDataFilter-----
|
||||||
AlarmEventDataFilter::AlarmEventDataFilter()
|
AlarmEventDataFilter::AlarmEventDataFilter()
|
||||||
|
|
@ -204,7 +205,7 @@ void AlarmEventDataModel::iniHeaderData()
|
||||||
m_headerData.emplace_back(SectionData("类型", 150, Type));
|
m_headerData.emplace_back(SectionData("类型", 150, Type));
|
||||||
m_headerData.emplace_back(SectionData("等级", 150, Severity));
|
m_headerData.emplace_back(SectionData("等级", 150, Severity));
|
||||||
m_headerData.emplace_back(SectionData("确认状态", 150, Status));
|
m_headerData.emplace_back(SectionData("确认状态", 150, Status));
|
||||||
m_headerData.emplace_back(SectionData("操作", 300, Operation));
|
m_headerData.emplace_back(SectionData("操作", 172, Operation));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlarmEventDataModel::setFilter(const AlarmEventDataFilter& filter)
|
void AlarmEventDataModel::setFilter(const AlarmEventDataFilter& filter)
|
||||||
|
|
@ -320,7 +321,25 @@ void AlarmEventDataModel::onRealTimeEventReceived(const EventData& event)
|
||||||
AlarmEventDataDelegate::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
AlarmEventDataDelegate::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
,m_tableView(view)
|
,m_tableView(view)
|
||||||
{}
|
{
|
||||||
|
m_btnConfirm.text = QString("确 认");
|
||||||
|
m_btnConfirm.textColor = QColor(34, 177, 16);
|
||||||
|
m_btnConfirm.borderColor = QColor(34, 177, 16);
|
||||||
|
m_btnConfirm.borderWidth = 1;
|
||||||
|
m_btnConfirm.borderRaius = 2;
|
||||||
|
m_btnConfirm.normalBgColor = Qt::transparent;
|
||||||
|
m_btnConfirm.hoverBgColor = QColor(34, 177, 16, 80);
|
||||||
|
m_btnConfirm.pressedBgColor = Qt::transparent;
|
||||||
|
|
||||||
|
m_btnReplay.text = QString("回 放");
|
||||||
|
m_btnReplay.textColor = QColor(86, 156, 214);
|
||||||
|
m_btnReplay.borderColor = QColor(86, 156, 214);
|
||||||
|
m_btnReplay.borderWidth = 1;
|
||||||
|
m_btnReplay.borderRaius = 2;
|
||||||
|
m_btnReplay.normalBgColor = Qt::transparent;
|
||||||
|
m_btnReplay.hoverBgColor = QColor(86, 156, 214, 80);
|
||||||
|
m_btnReplay.pressedBgColor = Qt::transparent;
|
||||||
|
}
|
||||||
|
|
||||||
AlarmEventDataDelegate::~AlarmEventDataDelegate()
|
AlarmEventDataDelegate::~AlarmEventDataDelegate()
|
||||||
{}
|
{}
|
||||||
|
|
@ -335,9 +354,9 @@ void AlarmEventDataDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
||||||
else
|
else
|
||||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 0));
|
painter->fillRect(opt.rect, QColor(11, 26, 33, 0));
|
||||||
|
|
||||||
//绘制单元格边框(只绘制右边框,每行的最后一个单元格不绘制)
|
|
||||||
if(m_tableView)
|
if(m_tableView)
|
||||||
{
|
{
|
||||||
|
//绘制单元格边框(只绘制右边框,每行的最后一个单元格不绘制)
|
||||||
painter->save();
|
painter->save();
|
||||||
QPen pen(QColor(60,60,60), 1, Qt::DotLine);
|
QPen pen(QColor(60,60,60), 1, Qt::DotLine);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
|
|
@ -347,10 +366,74 @@ void AlarmEventDataDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
||||||
painter->drawLine(opt.rect.topRight(), opt.rect.bottomRight());
|
painter->drawLine(opt.rect.topRight(), opt.rect.bottomRight());
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
//绘制操作按钮
|
||||||
|
if(index.column() == m_tableView->model()->columnCount() - 1)
|
||||||
|
{
|
||||||
|
int nMarginH = 10;
|
||||||
|
int nMarginV = 5;
|
||||||
|
int nSpacing = 10;
|
||||||
|
int nBtnWidth = (opt.rect.width() - nMarginH * 2 - nSpacing) * 0.5;
|
||||||
|
int nBtnHeight = opt.rect.height() - nMarginV * 2;
|
||||||
|
|
||||||
|
/*QStyleOptionButton btnConfirm;
|
||||||
|
btnConfirm.text = QString("确 认");
|
||||||
|
btnConfirm.rect = QRect(opt.rect.left() + nMarginH, opt.rect.top() + nMarginV, nBtnWidth, nBtnHeight);
|
||||||
|
btnConfirm.state |= QStyle::State_Enabled;
|
||||||
|
QStyleOptionButton btnReplay;
|
||||||
|
btnReplay.text = QString("回 放");
|
||||||
|
btnReplay.rect = QRect(btnConfirm.rect.right() + nSpacing, opt.rect.top() + nMarginV, nBtnWidth, nBtnHeight);
|
||||||
|
btnReplay.state |= QStyle::State_Enabled;
|
||||||
|
|
||||||
|
// 绘制按钮
|
||||||
|
QApplication::style()->drawControl(QStyle::CE_PushButton, &btnConfirm, painter);
|
||||||
|
QApplication::style()->drawControl(QStyle::CE_PushButtonLabel, &btnReplay, painter);*/
|
||||||
|
|
||||||
|
const_cast<AlarmEventDataDelegate*>(this)->m_btnConfirm.rect = QRect(opt.rect.left() + nMarginH, opt.rect.top() + nMarginV, nBtnWidth, nBtnHeight);
|
||||||
|
const_cast<AlarmEventDataDelegate*>(this)->m_btnReplay.rect = QRect(m_btnConfirm.rect.right() + nSpacing, opt.rect.top() + nMarginV, nBtnWidth, nBtnHeight);
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
//绘制‘确认’按钮
|
||||||
|
QPen rectPen;
|
||||||
|
rectPen.setColor(m_btnConfirm.borderColor);
|
||||||
|
rectPen.setWidth(m_btnConfirm.borderWidth);
|
||||||
|
painter->setPen(rectPen);
|
||||||
|
painter->setBrush(m_btnConfirm.normalBgColor);
|
||||||
|
painter->drawRoundedRect(m_btnConfirm.rect, m_btnConfirm.borderRaius, m_btnConfirm.borderRaius);
|
||||||
|
painter->setPen(m_btnConfirm.textColor);
|
||||||
|
painter->drawText(m_btnConfirm.rect, Qt::AlignCenter, m_btnConfirm.text);
|
||||||
|
//绘制‘回放’按钮
|
||||||
|
rectPen.setColor(m_btnReplay.borderColor);
|
||||||
|
rectPen.setWidth(m_btnReplay.borderWidth);
|
||||||
|
painter->setPen(rectPen);
|
||||||
|
painter->setBrush(m_btnReplay.normalBgColor);
|
||||||
|
painter->drawRoundedRect(m_btnReplay.rect, m_btnReplay.borderRaius, m_btnReplay.borderRaius);
|
||||||
|
painter->setPen(m_btnReplay.textColor);
|
||||||
|
painter->drawText(m_btnReplay.rect, Qt::AlignCenter, m_btnReplay.text);
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(opt.state.testFlag(QStyle::State_Selected))
|
||||||
|
{
|
||||||
|
//方法1:移除选中状态,防止选中改变文字颜色
|
||||||
|
//opt.state &= ~QStyle::State_Selected;
|
||||||
|
|
||||||
|
//方法2
|
||||||
|
QColor originalTextColor = opt.palette.color(QPalette::Text);
|
||||||
|
opt.palette.setColor(QPalette::HighlightedText, originalTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//绘制默认内容
|
//绘制默认内容
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AlarmEventDataDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
|
||||||
|
{
|
||||||
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -361,7 +444,7 @@ AlarmEventDataView::AlarmEventDataView(QWidget* parent)
|
||||||
m_tableView = new QTableView(this);
|
m_tableView = new QTableView(this);
|
||||||
m_tableView->verticalHeader()->setVisible(false);
|
m_tableView->verticalHeader()->setVisible(false);
|
||||||
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
//m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_tableView->setShowGrid(false);
|
m_tableView->setShowGrid(false);
|
||||||
//m_tableView->setStyleSheet("QHeaderView{background-color: rgb(40, 40, 40);} QHeaderView::section{background-color:transparent;}");
|
//m_tableView->setStyleSheet("QHeaderView{background-color: rgb(40, 40, 40);} QHeaderView::section{background-color:transparent;}");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue