From c6b513e64aa283ee22fab2b4ba862950bcafd28f Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Tue, 5 Sep 2023 15:18:49 +0800 Subject: [PATCH] fix(qt5.9.7): fits the Qt5.9.7 interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 适配Qt5.9.7接口,修复编译报错 --- src/widgets/kiran-label/kiran-label.cpp | 20 ++++++++++++-------- src/widgets/kiran-tips/kiran-tips.cpp | 6 +++++- test/kiran-image-selector-test.cpp | 4 ++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/widgets/kiran-label/kiran-label.cpp b/src/widgets/kiran-label/kiran-label.cpp index 6302357..3dcd0e5 100644 --- a/src/widgets/kiran-label/kiran-label.cpp +++ b/src/widgets/kiran-label/kiran-label.cpp @@ -1,14 +1,14 @@ /** - * Copyright (c) 2020 ~ 2022 KylinSec Co., Ltd. + * Copyright (c) 2020 ~ 2022 KylinSec Co., Ltd. * kiranwidgets-qt5 is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - * + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * * Author: liuxinhao */ @@ -73,7 +73,11 @@ QRectF KiranLabelPrivate::documentRect(QLabelPrivate *ld) QFlag(ld->align)); int m = ld->indent; if (m < 0 && q->frameWidth()) // no indent, but we do have a frame +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) m = q->fontMetrics().horizontalAdvance(QLatin1Char('x')) / 2 - ld->margin; +#else + m = q->fontMetrics().width(QLatin1Char('x')) / 2 - ld->margin; +#endif if (m > 0) { if (align & Qt::AlignLeft) diff --git a/src/widgets/kiran-tips/kiran-tips.cpp b/src/widgets/kiran-tips/kiran-tips.cpp index d5bcbf6..91d2e6f 100644 --- a/src/widgets/kiran-tips/kiran-tips.cpp +++ b/src/widgets/kiran-tips/kiran-tips.cpp @@ -231,7 +231,11 @@ QSize KiranTips::getRightSize() const QFontMetrics fontMetrics(font); QMargins layoutContentMargins = this->layout()->contentsMargins(); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) d_ptr->m_labelText->setFixedWidth(fontMetrics.horizontalAdvance(d_ptr->m_labelText->text()) + 10); +#else + d_ptr->m_labelText->setFixedWidth(fontMetrics.width(d_ptr->m_labelText->text()) + 10); +#endif d_ptr->m_labelText->setFixedHeight(fontMetrics.height()); QSize size; @@ -355,7 +359,7 @@ void KiranTipsPrivate::init() m_EnterAnimation->setEasingCurve(QEasingCurve::OutQuad); // clang-format off - connect(&m_fadeOutTimer, &QTimer::timeout, [this](){ + connect(&m_fadeOutTimer, &QTimer::timeout, [this](){ q_ptr->hideTip(); }); connect(m_EnterAnimation, &QPropertyAnimation::finished, [this](){ diff --git a/test/kiran-image-selector-test.cpp b/test/kiran-image-selector-test.cpp index 7651e07..cf306cd 100644 --- a/test/kiran-image-selector-test.cpp +++ b/test/kiran-image-selector-test.cpp @@ -43,8 +43,8 @@ private slots: void testItemSpacing() { - QList itemSpacingSet = {5,10,15,20,25,50,100,150,300,10}; - foreach ( const int& spacing, itemSpacingSet ) + QList itemSpacingSet = {5,10,15,20,25,50,100,150,300,10}; + foreach ( const quint64& spacing, itemSpacingSet ) { imageSelector->setItemSpacing(spacing); QCOMPARE(imageSelector->itemSpacing(),spacing); -- 2.33.0