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
qquickuniversalfocusrectangle.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
6#include <QtGui/qpixmap.h>
7#include <QtGui/qpainter.h>
8#include <QtGui/qpixmapcache.h>
9#include <QtQuick/private/qquickitem_p.h>
10
12
13QQuickUniversalFocusRectangle::QQuickUniversalFocusRectangle(QQuickItem *parent)
15{
16 QQuickItemPrivate::get(this)->setTransparentForPositioner(true);
17}
18
19void QQuickUniversalFocusRectangle::paint(QPainter *painter)
20{
21 if (!isVisible() || width() <= 0 || height() <= 0)
22 return;
23
24 QRect bounds = boundingRect().toAlignedRect();
25 const int boundsWidth = bounds.width();
26 const int boundsHeight = bounds.width();
27 const QString key = QStringLiteral("qquickuniversalfocusrectangle_%1_%2").arg(QString::number(boundsWidth), QString::number(boundsHeight));
28
29 QPixmap pixmap(boundsWidth, boundsHeight);
30 if (!QPixmapCache::find(key, &pixmap)) {
31 bounds.adjust(0, 0, -1, -1);
32 pixmap.fill(Qt::transparent);
33 QPainter p(&pixmap);
34
35 QPen pen;
36 pen.setWidth(1);
37 pen.setColor(Qt::white);
38 p.setPen(pen);
39 p.drawRect(bounds);
40
41 pen.setColor(Qt::black);
42 pen.setDashPattern(QList<qreal>(2, 1));
43 p.setPen(pen);
44 p.drawRect(bounds);
45
46 QPixmapCache::insert(key, pixmap);
47 }
48 painter->drawPixmap(0, 0, pixmap);
49}
50
51QT_END_NAMESPACE
52
53#include "moc_qquickuniversalfocusrectangle_p.cpp"
QObject * parent
Definition qobject.h:73
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
Combined button and popup list for selecting options.