Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
customstyle.cpp
Go to the documentation of this file.
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.h"
7
8CustomStyle::CustomStyle(const QWidget *widget)
9{
10 //! [0]
11 const QSpinBox *spinBox = qobject_cast<const QSpinBox *>(widget);
12 if (spinBox) {
13 //...
14 }
15 //! [0]
16}
17
18//! [2]
19void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
20 QPainter *painter, const QWidget *widget) const
21{
22 if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) {
23 QPolygon points(3);
24 int x = option->rect.x();
25 int y = option->rect.y();
26 int w = option->rect.width() / 2;
27 int h = option->rect.height() / 2;
28 x += (option->rect.width() - w) / 2;
29 y += (option->rect.height() - h) / 2;
30
31 if (element == PE_IndicatorSpinUp) {
32 points[0] = QPoint(x, y + h);
33 points[1] = QPoint(x + w, y + h);
34 points[2] = QPoint(x + w / 2, y);
35 } else { // PE_SpinBoxDown
36 points[0] = QPoint(x, y);
37 points[1] = QPoint(x + w, y);
38 points[2] = QPoint(x + w / 2, y + h);
39 }
40
41 if (option->state & State_Enabled) {
42 painter->setPen(option->palette.mid().color());
43 painter->setBrush(option->palette.buttonText());
44 } else {
45 painter->setPen(option->palette.buttonText().color());
46 painter->setBrush(option->palette.mid());
47 }
48 painter->drawPolygon(points);
49 } else {
50 QProxyStyle::drawPrimitive(element, option, painter, widget);
51 }
52}
53//! [2]
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
[2]