QtCanpool 3.3.0
载入中...
搜索中...
未找到
qtcompat.h
浏览该文件的文档.
1
5#ifndef QTCOMPAT_H
6#define QTCOMPAT_H
7
8#include <QtCore/QPoint>
9#include <QtGui/QHoverEvent>
10#include <QtGui/QMouseEvent>
11
12/*
13 * Small shims for Qt API that changed between Qt 5 and Qt 6.
14 *
15 * Qt 6 replaced the integer based pointer accessors of QMouseEvent and
16 * QHoverEvent with the QPointF based ones inherited from QSinglePointEvent and
17 * deprecated the old names, while Qt 5.15 only offers the old integer ones.
18 * These helpers pick whichever exists so that call sites stay free of
19 * #if QT_VERSION noise. They are header-only on purpose: src/libs is on the
20 * include path of both the CMake and the frozen qmake build.
21 */
22
24{
25
26inline QPoint globalMousePos(const QMouseEvent *event)
27{
28#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
29 return event->globalPosition().toPoint();
30#else
31 return event->globalPos();
32#endif
33}
34
35inline QPoint hoverPos(const QHoverEvent *event)
36{
37#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
38 return event->position().toPoint();
39#else
40 return event->pos();
41#endif
42}
43
44} // namespace QtCanpoolCompat
45
46#endif // QTCOMPAT_H
Copyright (C) 2026 maminjie canpool@163.com SPDX-License-Identifier: MulanPSL-2.0
Definition qtcompat.h:24
QPoint globalMousePos(const QMouseEvent *event)
Definition qtcompat.h:26
QPoint hoverPos(const QHoverEvent *event)
Definition qtcompat.h:35