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
qgraphicslayoutstyleinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qgraphicslayout_p.h"
7#include "qgraphicswidget.h"
8#include <QtWidgets/qstyle.h>
9#include <QtWidgets/qwidget.h>
10#include <QtWidgets/qapplication.h>
11
13
15 : m_layout(layout), m_style(nullptr)
16{
17 m_widget.reset(new QWidget); // pixelMetric might need a widget ptr
18 m_styleOption.initFrom(m_widget.get());
19 m_isWindow = m_styleOption.state & QStyle::State_Window;
20}
21
25
26qreal QGraphicsLayoutStyleInfo::combinedLayoutSpacing(QLayoutPolicy::ControlTypes controls1,
27 QLayoutPolicy::ControlTypes controls2,
28 Qt::Orientation orientation) const
29{
30 Q_ASSERT(style());
31 return style()->combinedLayoutSpacing(QSizePolicy::ControlTypes(int(controls1)), QSizePolicy::ControlTypes(int(controls2)),
32 orientation, const_cast<QStyleOption*>(&m_styleOption), widget());
33}
34
37 Qt::Orientation orientation) const
38{
39 Q_ASSERT(style());
41 orientation, const_cast<QStyleOption*>(&m_styleOption), widget());
42}
43
51
53{
54 return style()->pixelMetric(orientation == Qt::Vertical
57 const_cast<QStyleOption*>(&m_styleOption), widget());
58}
59
60QWidget *QGraphicsLayoutStyleInfo::widget() const { return m_widget.get(); }
61
63{
64 if (!m_style) {
65 Q_ASSERT(m_layout);
66 QGraphicsItem *item = m_layout->parentItem();
67 m_style = (item && item->isWidget()) ? static_cast<QGraphicsWidget*>(item)->style() : QApplication::style();
68 }
69 return m_style;
70}
71
static QStyle * style()
Returns the application's style object.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
bool isWidget() const
QGraphicsItem * parentItem() const
virtual qreal spacing(Qt::Orientation orientation) const override
virtual qreal perItemSpacing(QLayoutPolicy::ControlType control1, QLayoutPolicy::ControlType control2, Qt::Orientation orientation) const override
virtual qreal combinedLayoutSpacing(QLayoutPolicy::ControlTypes controls1, QLayoutPolicy::ControlTypes controls2, Qt::Orientation orientation) const override
QGraphicsLayoutStyleInfo(const QGraphicsLayoutPrivate *layout)
virtual qreal windowMargin(Qt::Orientation orientation) const override
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
QStyle * style() const
Returns a pointer to the widget's style.
The QStyleOption class stores the parameters used by QStyle functions.
QStyle::State state
void initFrom(const QWidget *w)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ State_Window
Definition qstyle.h:84
virtual int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=nullptr, QWidget *widget=nullptr) const
Definition qstyle.cpp:2371
@ PM_LayoutBottomMargin
Definition qstyle.h:515
@ PM_LayoutVerticalSpacing
Definition qstyle.h:517
@ PM_LayoutHorizontalSpacing
Definition qstyle.h:516
@ PM_LayoutRightMargin
Definition qstyle.h:514
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QVBoxLayout * layout
QGraphicsItem * item