Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
53f15e6
feat(anim): add hover transitions for button widgets
CyberWon Aug 29, 2026
e621c19
feat(anim): animate checkbox and radio hover and check states
CyberWon Aug 29, 2026
edec66b
feat(anim): animate combobox and spinbox body hover
CyberWon Aug 29, 2026
f5f3c87
feat(anim): animate row hover in list, table and tree views
CyberWon Aug 29, 2026
0ef0515
feat(anim): animate tab and menu item hover
CyberWon Aug 29, 2026
ededb4c
chore: ignore local example run script
CyberWon Aug 29, 2026
318e3a1
perf(widget): pause infinite animations when widgets are hidden
CyberWon Aug 29, 2026
e6d51cf
perf(anim): skip repaints while widgets are not visible
CyberWon Aug 29, 2026
b61e7e8
perf(anim): reuse animation objects across state transitions
CyberWon Aug 29, 2026
47be0b7
perf(style): repaint only the animated region for row hover and slide…
CyberWon Aug 29, 2026
c5cc882
perf(window): replace processEvents with a zero-delay timer for blur …
CyberWon Aug 29, 2026
6038087
perf(button): drop empty-property QPropertyAnimation timer hacks
CyberWon Aug 29, 2026
488b83b
perf(blur): downsample before exponential blur for large-radius backg…
CyberWon Aug 29, 2026
eb7c495
perf(popup): use window opacity instead of QGraphicsOpacityEffect
CyberWon Aug 29, 2026
be0e2bd
chore(include): drop unused QGraphicsOpacityEffect includes
CyberWon Aug 29, 2026
e0391e1
fix(appbar): keep native NSWindow behaviors on macOS for real maximize
CyberWon Sep 9, 2026
ee4415d
ci(example): normalize Windows paths in windeployqt install script
CyberWon Sep 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ __pycache__/
/Qt6.10.3/
/Qt/

# 本地运行脚本(个人用)
/run_example_local.sh

# 本地资源(体积大,不入库)
/PySide6Example/Resource/
/ElaWidgetToolsExample/Resource/
23 changes: 21 additions & 2 deletions ElaWidgetTools/DeveloperComponents/ElaCentralStackedWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
targetWidget->setVisible(false);
QPropertyAnimation* popupAnimation = new QPropertyAnimation(this, "pPopupAnimationYOffset");
connect(popupAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
if (!isVisible())
{
return;
}
update();
});
connect(popupAnimation, &QPropertyAnimation::finished, this, [=]() {
Expand All @@ -135,12 +139,20 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
_isDrawNewPix = false;
QPropertyAnimation* currentPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
connect(currentPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
if (!isVisible())
{
return;
}
update();
});
connect(currentPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
_isDrawNewPix = true;
QPropertyAnimation* targetPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
connect(targetPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
if (!isVisible())
{
return;
}
update();
});
connect(targetPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
Expand Down Expand Up @@ -201,6 +213,10 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
targetWidget->setVisible(false);
QPropertyAnimation* flipAnimation = new QPropertyAnimation(this, "pFlipAnimationRatio");
connect(flipAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
if (!isVisible())
{
return;
}
update();
});
connect(flipAnimation, &QPropertyAnimation::finished, this, [=]() {
Expand Down Expand Up @@ -231,8 +247,11 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
blurAnimation->setStartValue(40);
blurAnimation->setEndValue(2);
blurAnimation->start(QAbstractAnimation::DeleteWhenStopped);
QApplication::processEvents();
_containerStackedWidget->setCurrentIndex(nodeIndex);
// 用零延迟单发定时器代替 processEvents():保留“先渲染一帧模糊、再切页”的时序,
// 同时避免事件重入(重入可能在动画/页面截取进行中重新触发导航)
QTimer::singleShot(0, this, [=]() {
_containerStackedWidget->setCurrentIndex(nodeIndex);
});
break;
}
}
Expand Down
90 changes: 60 additions & 30 deletions ElaWidgetTools/DeveloperComponents/ElaCheckBoxStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <QDebug>
#include <QPainter>
#include <QPointer>
#include <QStyleOption>
#include <QVariantAnimation>

#include "ElaTheme.h"
ElaCheckBoxStyle::ElaCheckBoxStyle(QStyle* style)
Expand All @@ -28,6 +30,30 @@ void ElaCheckBoxStyle::drawControl(ControlElement element, const QStyleOption* o
if (const QStyleOptionButton* bopt = qstyleoption_cast<const QStyleOptionButton*>(option))
{
bool isEnabled = bopt->state.testFlag(QStyle::State_Enabled);
// 悬停与勾选过渡
bool isHovered = bopt->state.testFlag(QStyle::State_MouseOver);
bool isChecked = bopt->state.testFlag(QStyle::State_On) || bopt->state.testFlag(QStyle::State_NoChange);
if (_firstPaint)
{
_firstPaint = false;
_lastHovered = isHovered;
_lastChecked = isChecked;
_hoverRatio = isHovered ? 1 : 0;
_checkRatio = isChecked ? 1 : 0;
}
else
{
if (isHovered != _lastHovered)
{
_startRatioAnimation(&_hoverRatio, isHovered ? 1 : 0, 150, QEasingCurve::OutCubic, widget);
_lastHovered = isHovered;
}
if (isChecked != _lastChecked)
{
_startRatioAnimation(&_checkRatio, isChecked ? 1 : 0, 200, QEasingCurve::OutBack, widget);
_lastChecked = isChecked;
}
}
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
QRect checkBoxRect = bopt->rect;
Expand All @@ -36,42 +62,17 @@ void ElaCheckBoxStyle::drawControl(ControlElement element, const QStyleOption* o
checkRect.adjust(1, 1, -1, -1);
//复选框绘制
painter->setPen(Qt::NoPen);
if (bopt->state.testFlag(QStyle::State_On) || bopt->state.testFlag(QStyle::State_NoChange))
if (isChecked)
{
painter->setPen(Qt::NoPen);
if (bopt->state.testFlag(QStyle::State_Sunken))
{
painter->setBrush(ElaThemeColor(_themeMode, PrimaryPress));
}
else
{
if (bopt->state.testFlag(QStyle::State_MouseOver))
{
painter->setBrush(ElaThemeColor(_themeMode, PrimaryHover));
}
else
{
painter->setBrush(ElaThemeColor(_themeMode, PrimaryNormal));
}
}
painter->setBrush(bopt->state.testFlag(QStyle::State_Sunken) ? ElaThemeColor(_themeMode, PrimaryPress) : elaMixColor(ElaThemeColor(_themeMode, PrimaryNormal), ElaThemeColor(_themeMode, PrimaryHover), _hoverRatio));
}
else
{
if (bopt->state.testFlag(QStyle::State_Sunken))
{
painter->setPen(ElaThemeColor(_themeMode, BasicBorderDeep));
}
else
painter->setPen(ElaThemeColor(_themeMode, BasicBorderDeep));
if (!bopt->state.testFlag(QStyle::State_Sunken))
{
painter->setPen(ElaThemeColor(_themeMode, BasicBorderDeep));
if (bopt->state.testFlag(QStyle::State_MouseOver))
{
painter->setBrush(ElaThemeColor(_themeMode, BasicHover));
}
else
{
painter->setBrush(ElaThemeColor(_themeMode, BasicBase));
}
painter->setBrush(elaMixColor(ElaThemeColor(_themeMode, BasicBase), ElaThemeColor(_themeMode, BasicHover), _hoverRatio));
}
}
painter->drawRoundedRect(checkRect, 2, 2);
Expand All @@ -83,6 +84,12 @@ void ElaCheckBoxStyle::drawControl(ControlElement element, const QStyleOption* o
QFont iconFont = QFont("ElaAwesome");
iconFont.setPixelSize(_pCheckIndicatorWidth * 0.75);
painter->setFont(iconFont);
// 勾选弹出(缩放+透明度)
qreal scale = 0.6 + 0.4 * _checkRatio;
painter->translate(checkRect.center());
painter->scale(scale, scale);
painter->translate(-checkRect.center());
painter->setOpacity(qBound(0.0, _checkRatio, 1.0));
painter->drawText(checkRect, Qt::AlignCenter, QChar((unsigned short)ElaIconType::Check));
painter->restore();
}
Expand Down Expand Up @@ -132,3 +139,26 @@ int ElaCheckBoxStyle::pixelMetric(PixelMetric metric, const QStyleOption* option
}
return QProxyStyle::pixelMetric(metric, option, widget);
}

void ElaCheckBoxStyle::_startRatioAnimation(qreal* targetRatio, qreal endRatio, int duration, QEasingCurve::Type curve, const QWidget* widget) const
{
QVariantAnimation*& ratioAnimation = targetRatio == &_hoverRatio ? _hoverRatioAnimation : _checkRatioAnimation;
if (!ratioAnimation)
{
ratioAnimation = new QVariantAnimation;
QPointer<QWidget> widgetGuard = const_cast<QWidget*>(widget);
connect(ratioAnimation, &QVariantAnimation::valueChanged, this, [=](const QVariant& value) {
*targetRatio = value.toReal();
if (widgetGuard && widgetGuard->isVisible())
{
widgetGuard->update();
}
});
}
ratioAnimation->stop();
ratioAnimation->setDuration(duration);
ratioAnimation->setEasingCurve(QEasingCurve(curve));
ratioAnimation->setStartValue(*targetRatio);
ratioAnimation->setEndValue(endRatio);
ratioAnimation->start();
}
10 changes: 10 additions & 0 deletions ElaWidgetTools/DeveloperComponents/ElaCheckBoxStyle.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef ELACHECKBOXSTYLE_H
#define ELACHECKBOXSTYLE_H

#include <QEasingCurve>
#include <QProxyStyle>

#include "ElaDef.h"
class QVariantAnimation;
class ElaCheckBoxStyle : public QProxyStyle
{
Q_OBJECT
Expand All @@ -16,6 +18,14 @@ class ElaCheckBoxStyle : public QProxyStyle

private:
ElaThemeType::ThemeMode _themeMode;
mutable qreal _hoverRatio{0};
mutable qreal _checkRatio{0};
mutable QVariantAnimation* _hoverRatioAnimation{nullptr};
mutable QVariantAnimation* _checkRatioAnimation{nullptr};
mutable bool _lastHovered{false};
mutable bool _lastChecked{false};
mutable bool _firstPaint{true};
void _startRatioAnimation(qreal* targetRatio, qreal endRatio, int duration, QEasingCurve::Type curve, const QWidget* widget) const;
};

#endif // ELACHECKBOXSTYLE_H
19 changes: 13 additions & 6 deletions ElaWidgetTools/DeveloperComponents/ElaColorValueSliderStyle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ElaColorValueSliderStyle.h"

#include <QPainter>
#include <QPointer>
#include <QPropertyAnimation>
#include <QStyleOptionSlider>

Expand Down Expand Up @@ -71,7 +72,7 @@ void ElaColorValueSliderStyle::drawComplexControl(ComplexControl control, const
{
if (!_lastState.testFlag(QStyle::State_Sunken))
{
_startRadiusAnimation(sliderHandleRect.width() / 2.8, sliderHandleRect.width() / 4.5, const_cast<QWidget*>(widget));
_startRadiusAnimation(sliderHandleRect.width() / 2.8, sliderHandleRect.width() / 4.5, sliderHandleRect, const_cast<QWidget*>(widget));
_lastState = sopt->state;
}
painter->drawEllipse(QPointF(sliderHandleRect.center().x() + 1, sliderHandleRect.center().y() + 1), _circleRadius, _circleRadius);
Expand All @@ -83,12 +84,12 @@ void ElaColorValueSliderStyle::drawComplexControl(ComplexControl control, const
{
if (!_lastState.testFlag(QStyle::State_MouseOver))
{
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 2.8, const_cast<QWidget*>(widget));
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 2.8, sliderHandleRect, const_cast<QWidget*>(widget));
_lastState = sopt->state;
}
if (_lastState.testFlag(QStyle::State_Sunken))
{
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 2.8, const_cast<QWidget*>(widget));
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 2.8, sliderHandleRect, const_cast<QWidget*>(widget));
_lastState = sopt->state;
}
painter->drawEllipse(QPointF(sliderHandleRect.center().x() + 1, sliderHandleRect.center().y() + 1), _circleRadius, _circleRadius);
Expand All @@ -99,7 +100,7 @@ void ElaColorValueSliderStyle::drawComplexControl(ComplexControl control, const
{
if (_lastState.testFlag(QStyle::State_MouseOver) || _lastState.testFlag(QStyle::State_Sunken))
{
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 3.8, const_cast<QWidget*>(widget));
_startRadiusAnimation(_circleRadius, sliderHandleRect.width() / 3.8, sliderHandleRect, const_cast<QWidget*>(widget));
_lastState &= ~QStyle::State_MouseOver;
_lastState &= ~QStyle::State_Sunken;
}
Expand Down Expand Up @@ -145,13 +146,19 @@ int ElaColorValueSliderStyle::styleHint(StyleHint hint, const QStyleOption* opti
return QProxyStyle::styleHint(hint, option, widget, returnData);
}

void ElaColorValueSliderStyle::_startRadiusAnimation(qreal startRadius, qreal endRadius, QWidget* widget) const
void ElaColorValueSliderStyle::_startRadiusAnimation(qreal startRadius, qreal endRadius, const QRect& handleRect, QWidget* widget) const
{
ElaColorValueSliderStyle* style = const_cast<ElaColorValueSliderStyle*>(this);
QPropertyAnimation* circleRadiusAnimation = new QPropertyAnimation(style, "circleRadius");
// 手柄悬停过渡期间位置不变,脏区域即手柄矩形外扩 2px(含描边与抗锯齿溢出)
QRect animRect = handleRect.adjusted(-2, -2, 2, 2);
QPointer<QWidget> widgetGuard = widget;
connect(circleRadiusAnimation, &QPropertyAnimation::valueChanged, style, [=](const QVariant& value) {
this->_circleRadius = value.toReal();
widget->update(); });
if (widgetGuard && widgetGuard->isVisible())
{
widgetGuard->update(animRect);
} });
circleRadiusAnimation->setEasingCurve(QEasingCurve::InOutSine);
circleRadiusAnimation->setStartValue(startRadius);
circleRadiusAnimation->setEndValue(endRadius);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ElaColorValueSliderStyle : public QProxyStyle
QLinearGradient* _baseGradient{nullptr};
mutable QStyle::State _lastState{QStyle::State_None};
mutable qreal _circleRadius{0};
void _startRadiusAnimation(qreal startRadius, qreal endRadius, QWidget* widget) const;
void _startRadiusAnimation(qreal startRadius, qreal endRadius, const QRect& handleRect, QWidget* widget) const;
};

#endif // ELACOLORVALUESLIDERSTYLE_H
41 changes: 38 additions & 3 deletions ElaWidgetTools/DeveloperComponents/ElaComboBoxStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <QDebug>
#include <QPainter>
#include <QPainterPath>
#include <QPointer>
#include <QStyleOption>
#include <QVariantAnimation>

#include "ElaTheme.h"
ElaComboBoxStyle::ElaComboBoxStyle(QStyle* style)
Expand Down Expand Up @@ -148,12 +150,23 @@ void ElaComboBoxStyle::drawComplexControl(ComplexControl control, const QStyleOp
painter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
//背景绘制
bool isEnabled = copt->state.testFlag(QStyle::State_Enabled);
// 悬停过渡
bool isHovered = copt->state.testFlag(QStyle::State_MouseOver);
if (_firstPaint)
{
_firstPaint = false;
_lastHovered = isHovered;
_hoverRatio = isHovered ? 1 : 0;
}
else if (isHovered != _lastHovered)
{
_startHoverAnimation(isHovered ? 1 : 0, widget);
_lastHovered = isHovered;
}
painter->setPen(ElaThemeColor(_themeMode, BasicBorder));
painter->setBrush(isEnabled ? (copt->state.testFlag(QStyle::State_HasFocus) && copt->editable)
? ElaThemeColor(_themeMode, DialogBase)
: copt->state.testFlag(QStyle::State_MouseOver)
? ElaThemeColor(_themeMode, BasicHover)
: ElaThemeColor(_themeMode, BasicBase)
: elaMixColor(ElaThemeColor(_themeMode, BasicBase), ElaThemeColor(_themeMode, BasicHover), _hoverRatio)
: ElaThemeColor(_themeMode, BasicDisable));
QRect comboBoxRect = copt->rect;
comboBoxRect.adjust(_shadowBorderWidth, 1, -_shadowBorderWidth, -1);
Expand Down Expand Up @@ -260,3 +273,25 @@ QSize ElaComboBoxStyle::sizeFromContents(ContentsType type, const QStyleOption*
}
return QProxyStyle::sizeFromContents(type, option, size, widget);
}

void ElaComboBoxStyle::_startHoverAnimation(qreal endRatio, const QWidget* widget) const
{
if (!_hoverAnimation)
{
_hoverAnimation = new QVariantAnimation;
QPointer<QWidget> widgetGuard = const_cast<QWidget*>(widget);
connect(_hoverAnimation, &QVariantAnimation::valueChanged, this, [=](const QVariant& value) {
this->_hoverRatio = value.toReal();
if (widgetGuard && widgetGuard->isVisible())
{
widgetGuard->update();
}
});
}
_hoverAnimation->stop();
_hoverAnimation->setDuration(150);
_hoverAnimation->setEasingCurve(QEasingCurve::OutCubic);
_hoverAnimation->setStartValue(_hoverRatio);
_hoverAnimation->setEndValue(endRatio);
_hoverAnimation->start();
}
6 changes: 6 additions & 0 deletions ElaWidgetTools/DeveloperComponents/ElaComboBoxStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QProxyStyle>

#include "ElaDef.h"
class QVariantAnimation;
class ElaComboBoxStyle : public QProxyStyle
{
Q_OBJECT
Expand All @@ -22,6 +23,11 @@ class ElaComboBoxStyle : public QProxyStyle
private:
ElaThemeType::ThemeMode _themeMode;
int _shadowBorderWidth{6};
mutable qreal _hoverRatio{0};
mutable QVariantAnimation* _hoverAnimation{nullptr};
mutable bool _lastHovered{false};
mutable bool _firstPaint{true};
void _startHoverAnimation(qreal endRatio, const QWidget* widget) const;
};

#endif // ELACOMBOBOXSTYLE_H
4 changes: 4 additions & 0 deletions ElaWidgetTools/DeveloperComponents/ElaDrawerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void ElaDrawerContainer::doDrawerAnimation(bool isExpand)
_pContainerPix = grab(rect());
QPropertyAnimation* opacityAnimation = new QPropertyAnimation(this, "pOpacity");
connect(opacityAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
if (!isVisible())
{
return;
}
update();
});
connect(opacityAnimation, &QPropertyAnimation::finished, this, [=]() {
Expand Down
4 changes: 4 additions & 0 deletions ElaWidgetTools/DeveloperComponents/ElaDrawerHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void ElaDrawerHeader::doExpandOrCollapseAnimation()
{
QPropertyAnimation* rotateAnimation = new QPropertyAnimation(this, "pExpandIconRotate");
connect(rotateAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
if (!isVisible())
{
return;
}
update();
});
rotateAnimation->setDuration(300);
Expand Down
Loading
Loading