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
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
14 : QQuickPaintedItem(parent)
15{
16 QQuickItemPrivate::get(this)->setTransparentForPositioner(true);
17}
18
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);
31 bounds.adjust(0, 0, -1, -1);
34
35 QPen pen;
36 pen.setWidth(1);
38 p.setPen(pen);
39 p.drawRect(bounds);
40
42 pen.setDashPattern(QList<qreal>(2, 1));
43 p.setPen(pen);
44 p.drawRect(bounds);
45
47 }
49}
50
52
53#include "moc_qquickuniversalfocusrectangle_p.cpp"
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
\inmodule QtGui
Definition qpen.h:28
void setWidth(int width)
Sets the pen width to the given width in pixels with integer precision.
Definition qpen.cpp:592
void setColor(const QColor &color)
Sets the color of this pen's brush to the given color.
Definition qpen.cpp:705
void setDashPattern(const QList< qreal > &pattern)
Sets the dash pattern for this pen to the given pattern.
Definition qpen.cpp:463
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
bool isVisible() const
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
void paint(QPainter *painter) override
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
QQuickUniversalFocusRectangle(QQuickItem *parent=nullptr)
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:373
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
Combined button and popup list for selecting options.
@ white
Definition qnamespace.h:31
@ transparent
Definition qnamespace.h:47
@ black
Definition qnamespace.h:30
GLuint64 key
GLfloat GLfloat p
[1]
#define QStringLiteral(str)
widget render & pixmap
QPainter painter(this)
[7]