From a08314a2b94de3d8863593dc8f381fc42c50721b Mon Sep 17 00:00:00 2001 From: caomengxuan666 <2507560089@qq.com> Date: Thu, 24 Apr 2025 20:00:53 +0800 Subject: [PATCH] feat: add support for Qt6 and fix compilation issues - Replace deprecated QLayout::setMargin() with setContentsMargins(). - Replace QPalette::Foreground with QPalette::WindowText to adapt to Qt6's QPalette role changes. - Ensure compatibility with both Qt5 and Qt6 to avoid API-related compilation errors. Test Results: - Successfully compiles and runs on both Qt5 and Qt6 environments. - The fixes maintain functional consistency and do not introduce new issues. This update improves cross-version compatibility and provides better support for future migration to Qt6. --- components/components.pro | 1 + components/qtmaterialtabs.cpp | 2 +- examples/appbarsettingseditor.cpp | 4 ++++ examples/examples.pro | 2 +- examples/radiobuttonsettingseditor.cpp | 2 +- qt-material-widgets.pro | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/components/components.pro b/components/components.pro index d6080d5db..8395ae82a 100644 --- a/components/components.pro +++ b/components/components.pro @@ -1,5 +1,6 @@ TEMPLATE = lib CONFIG += staticlib +QT += statemachine SOURCES = \ qtmaterialavatar.cpp \ lib/qtmaterialstyle.cpp \ diff --git a/components/qtmaterialtabs.cpp b/components/qtmaterialtabs.cpp index dbc55bdbd..719feae85 100644 --- a/components/qtmaterialtabs.cpp +++ b/components/qtmaterialtabs.cpp @@ -33,7 +33,7 @@ void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init() q->setStyle(&QtMaterialStyle::instance()); tabLayout->setSpacing(0); - tabLayout->setMargin(0); + tabLayout->setContentsMargins(0, 0, 0, 0); } /*! diff --git a/examples/appbarsettingseditor.cpp b/examples/appbarsettingseditor.cpp index 5f2ce00af..5fdc0a595 100644 --- a/examples/appbarsettingseditor.cpp +++ b/examples/appbarsettingseditor.cpp @@ -12,7 +12,11 @@ AppBarSettingsEditor::AppBarSettingsEditor(QWidget *parent) { QLabel *label = new QLabel("Inbox"); label->setAttribute(Qt::WA_TranslucentBackground); +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) + label->setForegroundRole(QPalette::WindowText); +#else label->setForegroundRole(QPalette::Foreground); +#endif label->setContentsMargins(6, 0, 0, 0); QPalette palette = label->palette(); diff --git a/examples/examples.pro b/examples/examples.pro index 35d2438ca..b66b6efa2 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,4 +1,4 @@ -QT += core gui widgets +QT += core gui widgets statemachine TEMPLATE = app CONFIG += c++11 SOURCES = mainwindow.cpp \ diff --git a/examples/radiobuttonsettingseditor.cpp b/examples/radiobuttonsettingseditor.cpp index 2a039ce50..fd4be7931 100644 --- a/examples/radiobuttonsettingseditor.cpp +++ b/examples/radiobuttonsettingseditor.cpp @@ -47,7 +47,7 @@ RadioButtonSettingsEditor::RadioButtonSettingsEditor(QWidget *parent) layout->setAlignment(Qt::AlignCenter); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); setupForm(); diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index 5654f10a8..4766b36fe 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -1,4 +1,4 @@ -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets statemachine TARGET = qt-material-widgets TEMPLATE = subdirs