Skip to content

Commit

Permalink
调整窗口显示
Browse files Browse the repository at this point in the history
* 将一部分控件属性的设置移到ui文件中
* 调整主窗口大小
* 更换图像时自适应调整显示区域的尺寸
  • Loading branch information
miRoox committed Dec 16, 2019
1 parent cecb38a commit e4130da
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
8 changes: 5 additions & 3 deletions DIP-src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include "labeledslider.h"
#include "algorithms.h"
#include <algorithm>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QtCharts/QChart>
Expand Down Expand Up @@ -225,12 +226,15 @@ MainWindow::MainWindow(QWidget *parent)
scene->setSceneRect(scene->itemsBoundingRect());
auto current = ui->tabWidget->currentWidget();//注意:QGraphicsView::fitInView在使用时必须处于显示状态才能成功
ui->tabWidget->setCurrentWidget(tab);
auto splitter = tab->findChild<QSplitter*>();
Q_CHECK_PTR(splitter);
int prefSize = std::min(image.width(),splitter->height()); // 更换图像的时候调整显示区域尺寸
splitter->setSizes({prefSize,splitter->width()-prefSize});
imageView->fitInView(scene->itemsBoundingRect(),Qt::KeepAspectRatio);
imageView->updateGeometry();
ui->tabWidget->setCurrentWidget(current);//还原当前的Tab页
});
imageView->setScene(scene);
imageView->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
auto addActionToView = addActionTo(imageView);
addActionToView(tr("复制"),QKeySequence::Copy,[&image]{
QApplication::clipboard()->setImage(image);
Expand All @@ -253,7 +257,6 @@ MainWindow::MainWindow(QWidget *parent)
addActionToView(tr("适配视图大小"),QKeySequence(Qt::CTRL|Qt::Key_2),[imageView,scene]{
imageView->fitInView(scene->itemsBoundingRect(),Qt::KeepAspectRatio);
});
imageView->setContextMenuPolicy(Qt::ActionsContextMenu);
imageView->installEventFilter(this);
} // 图像视图

Expand All @@ -272,7 +275,6 @@ MainWindow::MainWindow(QWidget *parent)
tr("图片 (*.png *.jpg *.jpeg *.bmp *.xpm *.tif *tiff *.webp)"));
saveImage(image,fileName);
});
histView->setContextMenuPolicy(Qt::ActionsContextMenu);
chart->setTitle(histTitle);
connect(this,signal,[chart,&image]{
updateHistogramChart(chart,histogram(image));
Expand Down
56 changes: 49 additions & 7 deletions DIP-src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>1200</width>
<height>600</height>
</rect>
</property>
Expand All @@ -33,8 +33,22 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGraphicsView" name="originView"/>
<widget class="QtCharts::QChartView" name="originHistView"/>
<widget class="QGraphicsView" name="originView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="transformationAnchor">
<enum>QGraphicsView::AnchorUnderMouse</enum>
</property>
<property name="viewportUpdateMode">
<enum>QGraphicsView::BoundingRectViewportUpdate</enum>
</property>
</widget>
<widget class="QtCharts::QChartView" name="originHistView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
</widget>
</widget>
</item>
</layout>
Expand All @@ -49,8 +63,22 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGraphicsView" name="globalEnhView"/>
<widget class="QtCharts::QChartView" name="globalEnhHistView"/>
<widget class="QGraphicsView" name="globalEnhView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="transformationAnchor">
<enum>QGraphicsView::AnchorUnderMouse</enum>
</property>
<property name="viewportUpdateMode">
<enum>QGraphicsView::BoundingRectViewportUpdate</enum>
</property>
</widget>
<widget class="QtCharts::QChartView" name="globalEnhHistView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
</widget>
</widget>
</item>
</layout>
Expand All @@ -65,8 +93,22 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGraphicsView" name="localEnhView"/>
<widget class="QtCharts::QChartView" name="localEnhHistView"/>
<widget class="QGraphicsView" name="localEnhView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="transformationAnchor">
<enum>QGraphicsView::AnchorUnderMouse</enum>
</property>
<property name="viewportUpdateMode">
<enum>QGraphicsView::BoundingRectViewportUpdate</enum>
</property>
</widget>
<widget class="QtCharts::QChartView" name="localEnhHistView">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
</widget>
</widget>
</item>
</layout>
Expand Down

0 comments on commit e4130da

Please sign in to comment.