1#ifndef DA_QT5QT6_COMPAT_HPP
2#define DA_QT5QT6_COMPAT_HPP
3#include <QtCore/QtGlobal>
4#include <QtCore/QObject>
5#include <QtGui/QMouseEvent>
6#include <QtGui/QKeyEvent>
7#include <QtGui/QWheelEvent>
8#include <QtGui/QFontMetrics>
9#include <QtGui/QFontMetricsF>
10#include <QtGui/QColor>
28template<
typename EventType >
31#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
32 return event->globalPos();
34 return event->globalPosition().toPoint();
44template<
typename EventType >
47#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
50 return event->position().toPoint();
60template<
typename EventType >
63#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64 return event->pos().x();
66 return static_cast< int >(
event->position().x());
76template<
typename EventType >
79#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
80 return event->pos().y();
82 return static_cast< int >(
event->position().y());
94#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
97 return fm.horizontalAdvance(str);
109#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
110 return fm.width(str);
112 return fm.horizontalAdvance(str);
135#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
138 return e->angleDelta().y();
142inline void setNamedColor(QColor& c,
const char* colorName){
143#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
144 c.setNamedColor(colorName);
146 c = QColor::fromString(colorName);
149inline void setNamedColor(QColor& c,
const QString& colorName){
150#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
151 c.setNamedColor(colorName);
153 c = QColor::fromString(colorName);
QPoint eventPos(EventType *event)
获取事件的位置(QPoint)
Definition da_qt5qt6_compat.hpp:45
int eventPosY(EventType *event)
获取事件的y坐标
Definition da_qt5qt6_compat.hpp:77
int horizontalAdvance(const QFontMetrics &fm, const QString &str)
计算字符串的水平宽度(整数版本)
Definition da_qt5qt6_compat.hpp:92
int wheelEventDelta(QWheelEvent *e)
Get vertical wheel delta value compatible with Qt5 and Qt6
Definition da_qt5qt6_compat.hpp:133
QPoint eventGlobalPos(EventType *event)
获取事件的位置(QPoint)
Definition da_qt5qt6_compat.hpp:29
qreal horizontalAdvanceF(const QFontMetricsF &fm, const QString &str)
计算字符串的水平宽度(浮点数版本)
Definition da_qt5qt6_compat.hpp:107
int eventPosX(EventType *event)
获取事件的x坐标
Definition da_qt5qt6_compat.hpp:61
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44