feat: 新增分割左右栏,可以改变大小

Description: 新增分割左右栏,可以改变大小

Log: 新增分割左右栏,可以改变大小
Change-Id: I43b0cd961cbef523a4886a84f4dd358fd738d053
This commit is contained in:
liuminghang 2021-06-15 16:09:51 +08:00
parent 23d7a5a3a9
commit ecfc9f3f64
3 changed files with 28 additions and 6 deletions

View File

@ -11,6 +11,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QThread> #include <QThread>
#include <QMutexLocker> #include <QMutexLocker>
#include <QSplitter>
#include <DGuiApplicationHelper> #include <DGuiApplicationHelper>
#include <DMainWindow> #include <DMainWindow>
@ -95,13 +96,24 @@ void MainWidget::setupUi(QWidget *Widget)
m_plainTextEdit = new ResultTextView(Widget); m_plainTextEdit = new ResultTextView(Widget);
m_plainTextEdit->setObjectName(QStringLiteral("plainTextEdit")); m_plainTextEdit->setObjectName(QStringLiteral("plainTextEdit"));
connect(m_plainTextEdit, &ResultTextView::sigChangeSize, [ = ] {
loadingUi();
});
if (!m_imageview) { if (!m_imageview) {
m_imageview = new ImageView(); m_imageview = new ImageView();
} }
QSplitter *mainSplitter = new QSplitter(Qt::Horizontal); //新建水平分割器
m_horizontalLayout->addWidget(m_imageview); mainSplitter->setHandleWidth(1);//分割线的宽度
m_horizontalLayout->addWidget(m_plainTextEdit); mainSplitter->setChildrenCollapsible(false);//不允许把分割出的子窗口拖小到0最小值被限定为sizeHint或maxSize/minSize
mainSplitter->addWidget(m_imageview);//把ui中拖出的各个控件拿走放到分割器里面
mainSplitter->addWidget(m_plainTextEdit);
QList<int> 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_horizontalLayout->setStretch(0, 1);
m_mainGridLayout->addLayout(m_horizontalLayout, 0, 0, 1, 1); m_mainGridLayout->addLayout(m_horizontalLayout, 0, 0, 1, 1);
@ -212,6 +224,10 @@ void MainWidget::loadingUi()
m_loadingWidget->move(x, y); m_loadingWidget->move(x, y);
m_loadingTip->move(x - 20, y + 24); 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) void MainWidget::openImage(const QString &path)
@ -277,9 +293,6 @@ void MainWidget::loadString(const QString &string)
void MainWidget::resizeEvent(QResizeEvent *event) void MainWidget::resizeEvent(QResizeEvent *event)
{ {
loadingUi();
m_pwidget->setFixedSize(this->width(), this->height() - 48);
m_pwidget->move(0, 0);
return DWidget::resizeEvent(event); return DWidget::resizeEvent(event);
} }

View File

@ -42,3 +42,9 @@ void ResultTextView::contextMenuEvent(QContextMenuEvent *e)
} }
m_Menu->exec(QCursor::pos()); m_Menu->exec(QCursor::pos());
} }
void ResultTextView::resizeEvent(QResizeEvent *event)
{
emit sigChangeSize();
DPlainTextEdit::resizeEvent(event);
}

View File

@ -16,7 +16,10 @@ public:
protected: protected:
void contextMenuEvent(QContextMenuEvent *e) override; void contextMenuEvent(QContextMenuEvent *e) override;
void resizeEvent(QResizeEvent *event) override;
signals:
void sigChangeSize();
private: private:
QMenu *m_Menu; QMenu *m_Menu;
QAction *m_actCopy; QAction *m_actCopy;