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
qquickstyleitemscrollviewcorner.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7{
8 QStyleOptionSlider styleOption;
9 initStyleOption(styleOption);
10
11 StyleItemGeometry geometry;
12
13 // The size of the corner should be the width of the vertical
14 // scrollbar and the height of the horizontal scrollbar.
15 styleOption.orientation = Qt::Vertical;
16 const auto vScrollBarWidth = style()->sizeFromContents(QStyle::CT_ScrollBar, &styleOption, QSize(0, 0)).width();
17 styleOption.orientation = Qt::Horizontal;
18 const auto hScrollBarHeight = style()->sizeFromContents(QStyle::CT_ScrollBar, &styleOption, QSize(0, 0)).height();
19
20 geometry.minimumSize = QSize(vScrollBarWidth, hScrollBarHeight);
21 geometry.implicitSize = geometry.minimumSize;
22
23 return geometry;
24}
25
27{
28 QStyleOptionSlider styleOption;
29 initStyleOption(styleOption);
30
31 // Grab a center piece of a vertical scrollbar groove onto a QImage, and use this
32 // image to draw a corner. We draw the corner by first drawing the piece as it is, and
33 // then rotate it 90 degrees, clip it into a triangle, and draw it once more on top.
34 // The result is that we end up with one vertical and one horizontal triangle that
35 // together form a filled corner rectangle.
36
37 styleOption.orientation = Qt::Vertical;
38
39 const qreal scale = window()->effectiveDevicePixelRatio();
40 const int grooveWidth = minimumSize().width();
41 const int grooveHeight = minimumSize().height();
42 const QSize scrollBarMinSize = style()->sizeFromContents(QStyle::CT_ScrollBar, &styleOption, QSize(0, 0));
43 const QSize scrollBarSize = scrollBarMinSize + QSize(0, grooveHeight);
44 const int hStart = scrollBarMinSize.height() / 2;
45 const QRect targetImageRect(0, hStart * scale, grooveWidth * scale, grooveHeight * scale);
46
47 QImage scrollBarImage(scrollBarSize * scale, QImage::Format_ARGB32_Premultiplied);
48 scrollBarImage.setDevicePixelRatio(scale);
49 scrollBarImage.fill(Qt::transparent);
50 QPainter scrollBarPainter(&scrollBarImage);
51 styleOption.rect = QRect(QPoint(0, 0), scrollBarSize);
52 style()->drawComplexControl(QStyle::CC_ScrollBar, &styleOption, &scrollBarPainter);
53
54 // Draw vertical groove
55 painter->drawImage(QPoint(0, 0), scrollBarImage, targetImageRect);
56
58 path.moveTo(0, 0);
59 path.lineTo(0, grooveHeight);
60 path.lineTo(grooveWidth, grooveHeight);
61 path.closeSubpath();
62
64 transform.translate(grooveWidth, 0);
65 transform.rotate(90);
66
67 painter->save();
71 // Draw horizontal groove, clipped to a triangle
72 painter->drawImage(QPoint(0, 0), scrollBarImage, targetImageRect);
74}
75
76void QQuickStyleItemScrollViewCorner::initStyleOption(QStyleOptionSlider &styleOption) const
77{
78 initStyleOptionBase(styleOption);
79
82 styleOption.pageStep = 1000;
83 styleOption.minimum = 0;
84 styleOption.maximum = 1;
85 styleOption.sliderValue = 0;
86}
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation.
void restore()
Restores the current painter state (pops a saved state off the stack).
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
@ CompositionMode_Source
Definition qpainter.h:101
void setTransform(const QTransform &transform, bool combine=false)
\inmodule QtCore\reentrant
Definition qpoint.h:25
QStyle::SubControls subControls
QStyle::SubControls activeSubControls
QQuickWindow * window() const
Returns the window in which this item is rendered.
QQmlListProperty< QQuickTransform > transform
\qmlproperty list<Transform> QtQuick::Item::transform This property holds the list of transformations...
Definition qquickitem.h:110
void paintEvent(QPainter *painter) const override
layoutMarginsChangedQSize minimumSize
void initStyleOptionBase(QStyleOption &styleOption) const
static QStyle * style()
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
@ CT_ScrollBar
Definition qstyle.h:560
@ CC_ScrollBar
Definition qstyle.h:334
@ SC_ScrollBarGroove
Definition qstyle.h:357
@ SC_None
Definition qstyle.h:348
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
@ transparent
Definition qnamespace.h:47
GLuint GLenum GLenum transform
GLsizei const GLchar *const * path
GLenum GLenum GLenum GLenum GLenum scale
double qreal
Definition qtypes.h:187
QPainter painter(this)
[7]