1、事件系统不会往后传递,中途被截断导致信号不响应的问题。

 

2、svg的图片有些不能使用 foreiginObject 这些属性等等能力。

3、hover态和check的态这些不生效了!

4、把窗移动到另一个屏幕上时,分辨率不一致,此时发现出现一个问题:webview的窗口大小自己变化,父界面的ResizeEvent事件并没有响应。

5、高分辨下图片的缩放能力提供

1、主程序开启高分辨率的设置;

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

2、关键就是缩放拉伸的时候,要考虑物理像素和逻辑像素 (缩放的时候,需要使用 实际的物理大小)

3、比如使用QPixmap的话,需要单独设置这个设备像素比;

(保证软件自动拉伸的时候,不会拿一个缩小的图再来放大)

案例一 :、

(1) icon_label通过setFixedSize 可以实现一个 人眼看到的逻辑像素大小;

(2)实际图片设置进来的话,如果是二倍图,或者说如果是四倍图,那么需要优先设置一下,完成缩放到实际需要的物理大小。(就是显示的大小 * 缩放比(这个软件会自动再处理一次)

(3)设备需要自己再设置一下像素比 : 保证能够自动缩放到需要的像素。

void setHighDpiGif(QLabel* label, const QString& gifPath)
{
QMovie *movie = new QMovie(gifPath);
QSize originalSize = movie->currentImage().size();
// 获取设备像素比
qreal dpr = label->devicePixelRatioF();
// 计算适合高DPI的大小
QSize scaledSize = originalSize * dpr;
// 设置电影尺寸
movie->setScaledSize(scaledSize);
// 设置标签大小
label->setFixedSize(scaledSize);
// 设置缩放模式
label->setScaledContents(true);
label->setMovie(movie);
movie->start();
}
qreal dpr = icon_label->devicePixelRatioF();
// 计算实际需要的物理像素大小
QSize targetSize(40 * dpr, 40 * dpr);
// 缩放到物理像素大小
QPixmap scaled = icon_pixmap.scaled(targetSize,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
// 设置设备像素比
scaled.setDevicePixelRatio(dpr);
icon_label->setPixmap(scaled);
icon_label->setAlignment(Qt::AlignCenter);
”’
code

#include “animation_helper.h”
#include <QDebug>

QMovie* AnimationHelper::setup_high_dpi_animation(QLabel* label, const QString& file_path)
{
if (!label)
{
qWarning() << “AnimationHelper::setup_high_dpi_animation: label is null”;
return nullptr;
}

QMovie* movie = create_high_dpi_movie(label, file_path);
if (!movie)
{
qWarning() << “AnimationHelper::setup_high_dpi_animation: failed to create movie for” << file_path;
return nullptr;
}

movie->start();

return movie;
}

QMovie* AnimationHelper::create_high_dpi_movie(QLabel* label, const QString& file_path,
Qt::AspectRatioMode aspect_ratio,
Qt::TransformationMode transform)
{
if (!label)
{
qWarning() << “AnimationHelper::create_high_dpi_movie: label is null”;
return nullptr;
}

QMovie* movie = new QMovie(file_path, QByteArray(), label);

if (!movie || !movie->isValid())
{
qWarning() << “AnimationHelper::create_high_dpi_movie: invalid movie file” << file_path;
delete movie;
return nullptr;
}

movie->setCacheMode(QMovie::CacheAll);

// 连接帧变化信号,实时缩放每一帧
QObject::connect(movie, &QMovie::frameChanged, [label, movie, aspect_ratio, transform](int frame_number)
{
Q_UNUSED(frame_number)

if (!label || !movie)
{
return;
}

QPixmap frame = movie->currentPixmap();
if (frame.isNull())
{
return;
}

qreal dpr = label->devicePixelRatioF();
QSize logical_size = label->size();
QSize physical_size = logical_size * dpr;

// 缩放图像到物理像素尺寸
QPixmap scaled = frame.scaled(
physical_size,
aspect_ratio,
transform
);

// 设置正确的设备像素比
scaled.setDevicePixelRatio(dpr);

label->setPixmap(scaled);
});

return movie;
}

#pragma once

#include <QLabel>
#include <QMovie>

class AnimationHelper
{
public:
static QMovie* setup_high_dpi_animation(QLabel* label, const QString& file_path);
static QMovie* create_high_dpi_movie(QLabel* label, const QString& file_path,
Qt::AspectRatioMode aspect_ratio = Qt::KeepAspectRatio,
Qt::TransformationMode transform = Qt::SmoothTransformation);

private:
// 私有构造函数,防止实例化
AnimationHelper() = delete;
~AnimationHelper() = delete;
};
”’

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。