fix: 重写frame控件,增加信号,让子窗口大小跟随其变化

Description: 重写frame,让子窗口大小跟随其变化

Log: 重写frame,让子窗口大小跟随其变化
Change-Id: I72776ff6cf5245426c70cccd1960046ddca059ff
This commit is contained in:
liuminghang 2021-07-07 11:11:21 +08:00
parent 4b224d4d55
commit 5e16af0300
5 changed files with 45 additions and 6 deletions

View File

@ -28,7 +28,8 @@ HEADERS += src/mainwindow.h \
src/textloadwidget.h \ src/textloadwidget.h \
src/view/imageview.h \ src/view/imageview.h \
src/tessocrutils/tessocrutils.h \ src/tessocrutils/tessocrutils.h \
src/loadingwidget.h src/loadingwidget.h \
src/frame.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/mainwindow.cpp \ src/mainwindow.cpp \
@ -40,7 +41,8 @@ SOURCES += src/main.cpp \
src/resulttextview.cpp \ src/resulttextview.cpp \
src/view/imageview.cpp \ src/view/imageview.cpp \
src/tessocrutils/tessocrutils.cpp \ src/tessocrutils/tessocrutils.cpp \
src/loadingwidget.cpp src/loadingwidget.cpp \
src/frame.cpp
LIBS += -llept -ltesseract\ LIBS += -llept -ltesseract\

13
src/frame.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "frame.h"
Frame::Frame(QWidget *parent, Qt::WindowFlags f)
: QFrame(parent, f)
{
}
void Frame::resizeEvent(QResizeEvent *event)
{
emit sigFrameResize();
return QFrame::resizeEvent(event);
}

17
src/frame.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef FRAME_H
#define FRAME_H
#include <QFrame>
class Frame : public QFrame
{
Q_OBJECT
public:
Frame(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
signals:
void sigFrameResize();
protected:
void resizeEvent(QResizeEvent *event) override;
};
#endif // FRAME_H

View File

@ -1,6 +1,7 @@
#include "mainwidget.h" #include "mainwidget.h"
#include "view/imageview.h" #include "view/imageview.h"
#include "loadingwidget.h" #include "loadingwidget.h"
#include "frame.h"
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
@ -119,7 +120,7 @@ void MainWidget::setupUi(QWidget *Widget)
m_frameLayout->setContentsMargins(10, 10, 10, 10); m_frameLayout->setContentsMargins(10, 10, 10, 10);
//后面加一层窗口,左边空间间距20 //后面加一层窗口,左边空间间距20
m_frameStack = new QFrame(this); m_frameStack = new Frame(this);
m_frameStack->setFrameShape(QFrame::StyledPanel); m_frameStack->setFrameShape(QFrame::StyledPanel);
m_frameStack->setFrameShadow(QFrame::Raised); m_frameStack->setFrameShadow(QFrame::Raised);
m_frameStack->setLineWidth(0); m_frameStack->setLineWidth(0);
@ -146,6 +147,10 @@ void MainWidget::setupUi(QWidget *Widget)
//宽度最大值为440 //宽度最大值为440
m_frameStack->setMaximumWidth(440); m_frameStack->setMaximumWidth(440);
connect(m_frameStack, &Frame::sigFrameResize, this, [ = ] {
m_resultWidget->resize(QSize(m_frameStack->width() - 25, m_frameStack->height()));
});
m_loadingOcr = new loadingWidget(this); m_loadingOcr = new loadingWidget(this);
m_loadingOcr->setAlignment(Qt::AlignCenter); m_loadingOcr->setAlignment(Qt::AlignCenter);
@ -294,8 +299,8 @@ void MainWidget::deleteLoadingUi()
void MainWidget::loadingUi() void MainWidget::loadingUi()
{ {
if (m_loadingWidget && m_loadingTip && m_resultWidget) { if (m_loadingWidget && m_loadingTip && m_frameStack) {
int x = this->width() - m_resultWidget->width() / 2; int x = this->width() - m_frameStack->width() / 2;
int y = this->height() / 2 - 50; int y = this->height() / 2 - 50;
qDebug() << m_loadingWidget->width(); qDebug() << m_loadingWidget->width();
m_loadingWidget->setFixedSize(QSize(24, 24)); m_loadingWidget->setFixedSize(QSize(24, 24));

View File

@ -14,9 +14,11 @@
#include <DToolButton> #include <DToolButton>
#include "resulttextview.h" #include "resulttextview.h"
#include "textloadwidget.h" #include "textloadwidget.h"
#include "tessocrutils/tessocrutils.h" #include "tessocrutils/tessocrutils.h"
class Frame;
class QThread; class QThread;
class QGridLayout; class QGridLayout;
class QHBoxLayout; class QHBoxLayout;
@ -77,7 +79,7 @@ private:
QFrame *m_frame{nullptr}; QFrame *m_frame{nullptr};
QHBoxLayout *m_frameStackLayout{nullptr}; QHBoxLayout *m_frameStackLayout{nullptr};
QFrame *m_frameStack{nullptr}; Frame *m_frameStack{nullptr};
DLabel *m_tipIconLabel{nullptr}; DLabel *m_tipIconLabel{nullptr};
DHorizontalLine *m_line{nullptr}; DHorizontalLine *m_line{nullptr};