#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QItemDelegate>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class ItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
ItemDelegate(QObject* parent = 0) : QItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
QStyleOptionViewItem itemOption(option);
itemOption.palette.setColor(QPalette::HighlightedText, index.data(Qt::ForegroundRole).value<QColor>());
QColor co = index.data(Qt::BackgroundRole).value<QColor>();
co.setAlpha(50);
itemOption.palette.setColor(QPalette::Highlight, co);
QItemDelegate::paint(painter,itemOption,index);
}
};
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
#include "widget.h"
#include "./ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->tab->setItemDelegateForColumn(1, new ItemDelegate(this));
}
Widget::~Widget()
{
delete ui;
}
https://wormhole.app/3DEPqW#yWrAIDa6nZ45UqlbhvwINA
./UaExpert-1.5.1-331-x86_64.AppImage --appimage-extract
1773

被折叠的 条评论
为什么被折叠?



