代码拉取完成,页面将自动刷新
同步操作将从 aswg/自绘Qt所有控件 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "ResourceDelegate.h"
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
#include <QPen>
#include <QtDebug>
#include "dpi_util_win.h"
ResourceDelegate::ResourceDelegate(QAbstractItemView *parent)
: QStyledItemDelegate(parent)
, parent_(qobject_cast<QAbstractItemView*>(parent))
, updating(false)
{
scaleX = WinDpi::windowsDpiScaleX();
scaleY = WinDpi::windowsDpiScaleY();
// 当更改DPI的时候,更新最新的DPI
#ifdef Q_OS_WIN
connect(QApplication::primaryScreen(), &QScreen::logicalDotsPerInchChanged,
this, [this](){
scaleX = WinDpi::windowsDpiScaleX();
scaleY = WinDpi::windowsDpiScaleY();
});
#endif
}
void ResourceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem viewOption(option);
initStyleOption(&viewOption, index);
QPen pen;
pen.setColor(QColor("#50AFDB"));
pen.setWidth(1);
painter->setPen(pen);
QRect rectViewItem = viewOption.rect;
QRect rect = QRect(rectViewItem.x() + (viewOption.rect.width() - selectWidth) / 2,
rectViewItem.y() + (viewOption.rect.height() - selectHeight) / 2,
selectWidth * WinDpi::windowsDpiScaleX(),selectHeight * WinDpi::windowsDpiScaleY());
painter->drawRoundedRect(rect, 2, 2); // round rect
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
bool data = index.model()->data(index, Qt::UserRole).toBool();
qInfo() << __FUNCTION__ << data << index.row() << index.column();
if(data)
{
QPainterPath path;
path.moveTo(rect.x() + rect.width() * 1 / 3 , rect.y() + rect.height()* 1 / 4);
path.lineTo(rect.x() + rect.width() * 1 / 2 , rect.y() + rect.width()* 3 / 5);
path.lineTo(rect.x() + rect.width() + rect.width() * 1 / 4 ,rect.y());
path.lineTo(rect.x() + rect.width() * 1 / 2 , rect.y() + rect.height() * 13 / 15);
path.lineTo(rect.x() + rect.width() * 1 / 6 , rect.y() + rect.height() * 1 / 2);
path.lineTo(rect.x() + rect.width() * 1 / 3 , rect.y() + rect.height() * 1 / 4);
painter->fillPath(path, QColor("#40B400"));
}
painter->restore();
}
bool ResourceDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
QRect decorationRect = option.rect;
if (index.column() == HeaderList::UserRole_Checkbox_Select)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(event->type() == QEvent::MouseButtonDblClick)
{
if(!updating)
{
bool data = model->data(index, Qt::UserRole).toBool();
model->setData(index, !data, Qt::UserRole);
}
}
else if (event->type() == QEvent::MouseButtonPress && decorationRect.contains(mouseEvent->pos()))
{
if(!updating)
{
bool data = model->data(index, Qt::UserRole).toBool();
model->setData(index, !data, Qt::UserRole);
}
}
}
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
void ResourceDelegate::setUpdating(bool value)
{
updating = value;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。