自检页面调试完成
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "global.h"
|
||||
#include <QStyle>
|
||||
#include <QApplication>
|
||||
#include <QPushButton>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
|
||||
// 启动 500ms 闪烁:每 500ms 切换一次动态属性,QSS 据此在 40%↔100% 透明度间切换
|
||||
QTimer* startBlink(QWidget* w, const char* prop)
|
||||
@@ -43,6 +47,39 @@ QString cancelButtonStyle(int fontPx)
|
||||
.arg(fontPx).arg(C::DANGER);
|
||||
}
|
||||
|
||||
// ===================== 按钮焦点光圈 =====================
|
||||
ButtonFocusGlow::ButtonFocusGlow(const QColor& glow, QObject* parent)
|
||||
: QObject(parent), m_glow(glow)
|
||||
{
|
||||
}
|
||||
|
||||
bool ButtonFocusGlow::eventFilter(QObject* obj, QEvent* ev)
|
||||
{
|
||||
if (ev->type() == QEvent::FocusIn || ev->type() == QEvent::FocusOut) {
|
||||
QWidget* w = qobject_cast<QWidget*>(obj);
|
||||
if (w && qobject_cast<QPushButton*>(w)) {
|
||||
if (ev->type() == QEvent::FocusIn) {
|
||||
if (!w->graphicsEffect()) { // 挂一圈发光(偏移 0 → 四周光晕)
|
||||
QGraphicsDropShadowEffect* g = new QGraphicsDropShadowEffect(w);
|
||||
g->setBlurRadius(55); // 光晕大小(越大越强)
|
||||
g->setOffset(0, 0);
|
||||
g->setColor(m_glow);
|
||||
w->setGraphicsEffect(g);
|
||||
}
|
||||
} else {
|
||||
w->setGraphicsEffect(nullptr); // Qt 会删除旧效果
|
||||
}
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
void installButtonFocusGlow(QApplication* app)
|
||||
{
|
||||
if (app)
|
||||
app->installEventFilter(new ButtonFocusGlow(QColor("#7FBBFF"), app)); // 亮蓝,深色底更醒目
|
||||
}
|
||||
|
||||
QString appStyleSheet()
|
||||
{
|
||||
const QString s = QString(R"QSS(
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
#include <QColor>
|
||||
|
||||
class QApplication;
|
||||
|
||||
// ===================== 画布与全局常量 =====================
|
||||
// 屏幕分辨率(1920×1080 横屏);若部署在更低分辨率屏,可按同一比例整体缩放
|
||||
@@ -118,6 +121,24 @@ void stopBlink(QWidget* w, const char* prop = "blink");
|
||||
// 退出/取消按钮预设样式:被选中(悬停/按下/焦点)时红底白字
|
||||
QString cancelButtonStyle(int fontPx = 60);
|
||||
|
||||
// ===================== 按钮焦点光圈 =====================
|
||||
// 全局事件过滤器:任意 QPushButton 获得焦点时,在其四周加一圈发光(QSS 无法实现光晕)
|
||||
class ButtonFocusGlow : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ButtonFocusGlow(const QColor& glow = QColor("#3D8BFD"), QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* ev) override;
|
||||
|
||||
private:
|
||||
QColor m_glow;
|
||||
};
|
||||
|
||||
// 为整个应用安装按钮焦点光圈
|
||||
void installButtonFocusGlow(QApplication* app);
|
||||
|
||||
// 全局 QSS 样式表
|
||||
QString appStyleSheet();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user