diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 09b321c..8bc556c 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -95,13 +96,24 @@ void MainWidget::setupUi(QWidget *Widget) m_plainTextEdit = new ResultTextView(Widget); m_plainTextEdit->setObjectName(QStringLiteral("plainTextEdit")); + connect(m_plainTextEdit, &ResultTextView::sigChangeSize, [ = ] { + loadingUi(); + }); if (!m_imageview) { m_imageview = new ImageView(); } - - m_horizontalLayout->addWidget(m_imageview); - m_horizontalLayout->addWidget(m_plainTextEdit); + 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); + QList list; + list << 600 << 250; + mainSplitter->setSizes(list); +// m_horizontalLayout->addWidget(m_imageview); +// m_horizontalLayout->addWidget(m_plainTextEdit); + m_horizontalLayout->addWidget(mainSplitter); m_horizontalLayout->setStretch(0, 1); m_mainGridLayout->addLayout(m_horizontalLayout, 0, 0, 1, 1); @@ -212,6 +224,10 @@ void MainWidget::loadingUi() m_loadingWidget->move(x, y); m_loadingTip->move(x - 20, y + 24); } + if (m_pwidget) { + m_pwidget->setFixedSize(this->width(), this->height() - 48); + m_pwidget->move(0, 0); + } } void MainWidget::openImage(const QString &path) @@ -277,9 +293,6 @@ void MainWidget::loadString(const QString &string) void MainWidget::resizeEvent(QResizeEvent *event) { - loadingUi(); - m_pwidget->setFixedSize(this->width(), this->height() - 48); - m_pwidget->move(0, 0); return DWidget::resizeEvent(event); } diff --git a/src/resulttextview.cpp b/src/resulttextview.cpp index 673c3b4..5a832f8 100644 --- a/src/resulttextview.cpp +++ b/src/resulttextview.cpp @@ -42,3 +42,9 @@ void ResultTextView::contextMenuEvent(QContextMenuEvent *e) } m_Menu->exec(QCursor::pos()); } + +void ResultTextView::resizeEvent(QResizeEvent *event) +{ + emit sigChangeSize(); + DPlainTextEdit::resizeEvent(event); +} diff --git a/src/resulttextview.h b/src/resulttextview.h index 464157d..b0f78a4 100644 --- a/src/resulttextview.h +++ b/src/resulttextview.h @@ -16,7 +16,10 @@ public: protected: void contextMenuEvent(QContextMenuEvent *e) override; + void resizeEvent(QResizeEvent *event) override; +signals: + void sigChangeSize(); private: QMenu *m_Menu; QAction *m_actCopy;