Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
9{
11 const QSpinBox *spinBox = qobject_cast<const QSpinBox *>(widget);
12 if (spinBox) {
14 }
16}
17
20 QPainter *painter, const QWidget *widget) const
21{
22 if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) {
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 }
49 } else {
52 }
54}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
[2]
CustomStyle(const QWidget *widget)
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
\reimp
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
The QStyleOption class stores the parameters used by QStyle functions.
@ State_Enabled
Definition qstyle.h:67
PrimitiveElement
This enum describes the various primitive elements.
Definition qstyle.h:102
@ PE_IndicatorSpinDown
Definition qstyle.h:137
@ PE_IndicatorSpinUp
Definition qstyle.h:140
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLenum option
QPainter painter(this)
[7]
QSpinBox * spinBox
[0]