From dabea64329e35c5bbfa31899202b656290b62965 Mon Sep 17 00:00:00 2001 From: Zhang Yong Date: Tue, 15 Jun 2021 20:53:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=97=A0=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E7=BB=93=E6=9E=9C=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加无识别结果提示 Log: 识别结果展示相关 Change-Id: I74847ee2847175b8de0f6ec49a0a086cb1cdacc3 --- src/mainwidget.cpp | 24 +++++++++++++++++++++++- src/mainwidget.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 7ef6130..a4f338c 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -107,11 +107,22 @@ void MainWidget::setupUi(QWidget *Widget) if (!m_imageview) { m_imageview = new ImageView(); } + + m_resultWidget = new QStackedWidget(this); + m_resultWidget->setFocusPolicy(Qt::NoFocus); + m_resultWidget->addWidget(m_plainTextEdit); + + m_noResult = new DLabel(this); + m_noResult->setAlignment(Qt::AlignCenter); + m_noResult->setText(tr("No text recognized")); + + m_resultWidget->addWidget(m_noResult); + QSplitter *mainSplitter = new QSplitter(Qt::Horizontal); //新建水平分割器 mainSplitter->setHandleWidth(1);//分割线的宽度 mainSplitter->setChildrenCollapsible(false);//不允许把分割出的子窗口拖小到0,最小值被限定为sizeHint或maxSize/minSize mainSplitter->addWidget(m_imageview);//把ui中拖出的各个控件拿走,放到分割器里面 - mainSplitter->addWidget(m_plainTextEdit); + mainSplitter->addWidget(m_resultWidget); QList list; list << 600 << 250; mainSplitter->setSizes(list); @@ -287,17 +298,28 @@ void MainWidget::openImage(const QImage &img) void MainWidget::loadHtml(const QString &html) { if (!html.isEmpty()) { + m_resultWidget->setCurrentWidget(m_plainTextEdit); m_plainTextEdit->appendHtml(html); + } else { + resultEmpty(); } } void MainWidget::loadString(const QString &string) { if (!string.isEmpty()) { + m_resultWidget->setCurrentWidget(m_plainTextEdit); m_plainTextEdit->appendPlainText(string); + } else { + resultEmpty(); } } +void MainWidget::resultEmpty() +{ + m_resultWidget->setCurrentWidget(m_noResult); +} + void MainWidget::resizeEvent(QResizeEvent *event) { return DWidget::resizeEvent(event); diff --git a/src/mainwidget.h b/src/mainwidget.h index ed21dda..6c2fd4e 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -8,6 +8,7 @@ #include #include +#include #include "resulttextview.h" #include "textloadwidget.h" @@ -42,6 +43,7 @@ public: void loadHtml(const QString &html); void loadString(const QString &string); + void resultEmpty(); protected: void resizeEvent(QResizeEvent *event); @@ -75,6 +77,9 @@ private: QMutex m_mutex; RecognitionResult m_result; QImage *m_currentImg{nullptr}; + + QStackedWidget *m_resultWidget{nullptr}; + DLabel *m_noResult{nullptr}; signals: void sigResult(const QString &);