From 2036239a4f28aaf9034808bb69ac1c3a78d9cb73 Mon Sep 17 00:00:00 2001 From: liuminghang Date: Wed, 23 Jun 2021 14:10:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dbug84917?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 设置第一次居中,第二次打开不再居中 Log: 与窗口有关 Bug: https://pms.uniontech.com/zentao/bug-view-84917.html Change-Id: I49fdf12ffb981edb1408e27ac1a3de31cb2dd4a1 --- src/mainwindow.cpp | 4 +--- src/ocrapplication.cpp | 24 +++++++++++++++++++----- src/ocrapplication.h | 4 +++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index efd99d9..7aa92f8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,7 +27,6 @@ #include #include -#include MainWindow::MainWindow(QWidget *parent) : DMainWindow(parent) @@ -39,7 +38,6 @@ MainWindow::MainWindow(QWidget *parent) this->setCentralWidget(m_mainWidget); this->resize(840, 550); this->setMinimumSize(840, 550); - Dtk::Widget::moveToCenter(this); } MainWindow::~MainWindow() @@ -56,6 +54,6 @@ bool MainWindow::openFile(const QString &filePaths) bool MainWindow::openImage(const QImage &image, const QString &name) { - m_mainWidget->openImage(image,name); + m_mainWidget->openImage(image, name); return true; } diff --git a/src/ocrapplication.cpp b/src/ocrapplication.cpp index 0fb2d57..88454c4 100644 --- a/src/ocrapplication.cpp +++ b/src/ocrapplication.cpp @@ -21,7 +21,7 @@ #include "ocrapplication.h" #include "mainwindow.h" - +#include OcrApplication::OcrApplication(QObject *parent) : QObject(parent) { @@ -30,11 +30,17 @@ OcrApplication::OcrApplication(QObject *parent) : QObject(parent) bool OcrApplication::openFile(QString filePath) { + + qDebug() << __FUNCTION__ << __LINE__ << filePath; MainWindow *win = new MainWindow(); win->openFile(filePath); - win->resize(800, 600); win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } return true; } @@ -43,16 +49,24 @@ void OcrApplication::openImage(QImage image) qDebug() << __FUNCTION__ << __LINE__ << image.size(); MainWindow *win = new MainWindow(); win->openImage(image); - win->resize(800, 600); win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } } void OcrApplication::openImageAndName(QImage image, QString imageName) { qDebug() << __FUNCTION__ << __LINE__ << image.size(); MainWindow *win = new MainWindow(); - win->openImage(image,imageName); - win->resize(800, 600); + win->openImage(image, imageName); win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } } diff --git a/src/ocrapplication.h b/src/ocrapplication.h index 72e435d..23f982b 100644 --- a/src/ocrapplication.h +++ b/src/ocrapplication.h @@ -37,13 +37,15 @@ public: Q_INVOKABLE void openImage(QImage image); - Q_INVOKABLE void openImageAndName( QImage image, QString imageName); + Q_INVOKABLE void openImageAndName(QImage image, QString imageName); signals: public slots: +private: + int m_loadingCount{0};//启动次数 }; #endif // OCRAPPLICATION_H