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
qmacstyle_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant reason:default
4
5#ifndef QMACSTYLE_P_H
6#define QMACSTYLE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/qtguiglobal.h>
20
21#if defined(QT_WIDGETS_LIB) && defined(QT_QUICK_LIB)
22# error "Cannot use QtGui Mac style with both Widgets and Quick"
23#endif
24
25#if defined(QT_WIDGETS_LIB)
26# define OPTIONAL_WIDGET_ARGUMENT , const QWidget *w = nullptr
27# define FORWARD_OPTIONAL_WIDGET_ARGUMENT , w
28# else
29# define OPTIONAL_WIDGET_ARGUMENT
30# define FORWARD_OPTIONAL_WIDGET_ARGUMENT
31#endif
32
33#include <AppKit/NSApplication.h>
34
35QT_BEGIN_NAMESPACE
36
37class QPainter;
38
39/*
40 Helper class to ensure that the Mac style in Widgets and Quick
41 draw their NSViews and NSCells with the correct appearance,
42 as the native controls use NSAppearance.currentDrawingAppearance
43 instead of NSApp.effectiveAppearance when drawing.
44
45 Due to the duplicated class hierarchies between Widgets and Quick
46 for the styles, with the Quick styles missing the QWidget pointer
47 in the function parameters, we have to opt for an awkward macro
48 to solve this.
49*/
50template <typename Style, typename StyleOption, typename StyleOptionComplex>
51class QMacApperanceStyle : public Style
52{
53public:
54 void drawPrimitive(typename Style::PrimitiveElement pe, const StyleOption *opt, QPainter *p
55 OPTIONAL_WIDGET_ARGUMENT) const override
56 {
57 [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
58 Style::drawPrimitive(pe, opt, p
60 }];
61 }
62
63 void drawControl(typename Style::ControlElement element, const StyleOption *opt, QPainter *p
64 OPTIONAL_WIDGET_ARGUMENT) const override
65 {
66 [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
67 Style::drawControl(element, opt, p
69 }];
70 }
71
72 void drawComplexControl(typename Style::ComplexControl cc, const StyleOptionComplex *opt, QPainter *p
73 OPTIONAL_WIDGET_ARGUMENT) const override
74 {
75 [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
76 Style::drawComplexControl(cc, opt, p
78 }];
79 }
80};
81
82QT_END_NAMESPACE
83
84#endif // QMACSTYLE_P_H
void drawPrimitive(typename Style::PrimitiveElement pe, const StyleOption *opt, QPainter *p OPTIONAL_WIDGET_ARGUMENT) const override
Definition qmacstyle_p.h:54
void drawComplexControl(typename Style::ComplexControl cc, const StyleOptionComplex *opt, QPainter *p OPTIONAL_WIDGET_ARGUMENT) const override
Definition qmacstyle_p.h:72
void drawControl(typename Style::ControlElement element, const StyleOption *opt, QPainter *p OPTIONAL_WIDGET_ARGUMENT) const override
Definition qmacstyle_p.h:63
friend class QPainter
#define OPTIONAL_WIDGET_ARGUMENT
Definition qmacstyle_p.h:29
#define FORWARD_OPTIONAL_WIDGET_ARGUMENT
Definition qmacstyle_p.h:30