1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtWidgets>
5
6#include "../customstyle/customstyle.h"
7
8void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
9 QPainter *painter, const QWidget *widget) const
10{
11
12//![0]
13 switch (element) {
14 case (PE_PanelItemViewItem): {
15 painter->save();
16
17 QPoint topLeft = option->rect.topLeft();
18 QPoint bottomRight = option->rect.topRight();
19 QLinearGradient backgroundGradient(topLeft, bottomRight);
20 backgroundGradient.setColorAt(pos: 0.0, color: QColor(Qt::yellow).lighter(f: 190));
21 backgroundGradient.setColorAt(pos: 1.0, color: Qt::white);
22 painter->fillRect(option->rect, QBrush(backgroundGradient));
23
24 painter->restore();
25 break;
26 }
27 default:
28 QProxyStyle::drawPrimitive(element, option, painter, widget);
29 }
30//![0]
31}
32

source code of qtbase/src/widgets/doc/snippets/customviewstyle/customviewstyle.cpp