From 8bbe402a63e4647564eb8bb3c84c12553c0e6cde Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Thu, 19 Mar 2026 16:52:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=83=8F=E7=AD=89=E6=AF=94=E4=BE=8B?= =?UTF-8?q?=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HPPA/AspectRatioLabel.cpp | 28 ++++++++++++++++++++++++++++ HPPA/AspectRatioLabel.h | 22 ++++++++++++++++++++++ HPPA/HPPA.cpp | 18 ++++++++++++++++-- HPPA/HPPA.h | 2 ++ HPPA/HPPA.ui | 20 ++++++++------------ HPPA/HPPA.vcxproj | 2 ++ HPPA/HPPA.vcxproj.filters | 6 ++++++ HPPA/about.ui | 2 +- 8 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 HPPA/AspectRatioLabel.cpp create mode 100644 HPPA/AspectRatioLabel.h diff --git a/HPPA/AspectRatioLabel.cpp b/HPPA/AspectRatioLabel.cpp new file mode 100644 index 0000000..92ba88c --- /dev/null +++ b/HPPA/AspectRatioLabel.cpp @@ -0,0 +1,28 @@ +#include "stdafx.h" +#include "AspectRatioLabel.h" + +AspectRatioLabel::AspectRatioLabel(QWidget* parent) + : QLabel(parent) +{ + setAlignment(Qt::AlignCenter); +} + +void AspectRatioLabel::setOriginalPixmap(const QPixmap& pixmap) +{ + m_originalPixmap = pixmap; + updateScaledPixmap(); +} + +void AspectRatioLabel::resizeEvent(QResizeEvent* event) +{ + QLabel::resizeEvent(event); + updateScaledPixmap(); +} + +void AspectRatioLabel::updateScaledPixmap() +{ + if (m_originalPixmap.isNull()) + return; + + setPixmap(m_originalPixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} diff --git a/HPPA/AspectRatioLabel.h b/HPPA/AspectRatioLabel.h new file mode 100644 index 0000000..def1e72 --- /dev/null +++ b/HPPA/AspectRatioLabel.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +class AspectRatioLabel : public QLabel +{ + Q_OBJECT + +public: + explicit AspectRatioLabel(QWidget* parent = nullptr); + + void setOriginalPixmap(const QPixmap& pixmap); + +protected: + void resizeEvent(QResizeEvent* event) override; + +private: + void updateScaledPixmap(); + QPixmap m_originalPixmap; +}; diff --git a/HPPA/HPPA.cpp b/HPPA/HPPA.cpp index 9ebeb4c..799fed0 100644 --- a/HPPA/HPPA.cpp +++ b/HPPA/HPPA.cpp @@ -486,7 +486,7 @@ sizePolicy1.setHeightForWidth(graphicsView_delete->sizePolicy().hasHeightForWidt initControlTabwidget(); m_tabManager = new TabManager(ui.controlTabWidget, this); - ui.mDockWidgetSpectrometer->setWidget(tmp(ui.dockWidgetContents_4)); + ui.mDockWidgetSpectrometer->setWidget(tmp(ui.controlContents)); //3D模型看板 ui.mDockWidgetSimulator->setTile(QString::fromLocal8Bit("3D模型")); @@ -949,7 +949,21 @@ void HPPA::updateImagerPicture(const QString& actionName) QPixmap pixmap(picPath); if (!pixmap.isNull()) { - ui.imagerPictureLabel->setPixmap(pixmap); + QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); + const int threshold = 220; + for (int y = 0; y < img.height(); ++y) + { + QRgb* line = reinterpret_cast(img.scanLine(y)); + for (int x = 0; x < img.width(); ++x) + { + if (qRed(line[x]) >= threshold && qGreen(line[x]) >= threshold && qBlue(line[x]) >= threshold) + { + line[x] = qRgba(qRed(line[x]), qGreen(line[x]), qBlue(line[x]), 0); + } + } + } + ui.imagerPictureLabel->setAttribute(Qt::WA_TranslucentBackground); + ui.imagerPictureLabel->setOriginalPixmap(QPixmap::fromImage(img)); } } } diff --git a/HPPA/HPPA.h b/HPPA/HPPA.h index 3c00340..60659c6 100644 --- a/HPPA/HPPA.h +++ b/HPPA/HPPA.h @@ -67,6 +67,8 @@ #include "MapToolSpectral.h" #include "MapTools.h" +#include "AspectRatioLabel.h" + #define PI 3.1415926 QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用 diff --git a/HPPA/HPPA.ui b/HPPA/HPPA.ui index 0536d81..ca19e65 100644 --- a/HPPA/HPPA.ui +++ b/HPPA/HPPA.ui @@ -251,9 +251,9 @@ QToolBar QToolButton:hover { 2 - + - QWidget #dockWidgetContents_4 + QWidget #controlContents { background-color: #0E1C4C; @@ -424,22 +424,13 @@ QSlider::handle:horizontal:pressed { 10 - + 0 0 - - - - - true - - - Qt::AlignCenter - @@ -1173,6 +1164,11 @@ QPushButton:pressed
CustomDockWidgetBase.h
1 + + AspectRatioLabel + QLabel +
AspectRatioLabel.h
+
diff --git a/HPPA/HPPA.vcxproj b/HPPA/HPPA.vcxproj index 7cf4959..040a468 100644 --- a/HPPA/HPPA.vcxproj +++ b/HPPA/HPPA.vcxproj @@ -106,6 +106,7 @@ + @@ -194,6 +195,7 @@ + diff --git a/HPPA/HPPA.vcxproj.filters b/HPPA/HPPA.vcxproj.filters index 2aa38ac..23aa042 100644 --- a/HPPA/HPPA.vcxproj.filters +++ b/HPPA/HPPA.vcxproj.filters @@ -190,6 +190,9 @@ Source Files + + Source Files + @@ -306,6 +309,9 @@ Header Files + + Header Files + diff --git a/HPPA/about.ui b/HPPA/about.ui index 9226048..b4f050e 100644 --- a/HPPA/about.ui +++ b/HPPA/about.ui @@ -196,7 +196,7 @@ QPushButton:pressed - C:/Users/73505/.designer/backup/icon/all/png/Group 356_slices/Group 356.png + icon/all/png/Group 356_slices/Group 356@2x.png