一、设计
对功能和模块进行分析,然后设计对应的模块,将每个模块都用widget展示作为组件。
工程结构示例:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/38364cbeaa4924695fb7534f51ea1f42.png)
二、完成模块
代码分别设计各个组件,合适即可
三、主界面连接
主界面连接各个子模块。
在这里插入代码片#include "AutoFlawDetection.h"
#include<QVBoxLayout>
#include <QPainter>
AutoFlawDetection::AutoFlawDetection(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->IintView();
}
void AutoFlawDetection::IintView()
{
TitleWidget *titlebar = new TitleWidget(this);
QVBoxLayout *layouttitlebar = new QVBoxLayout();
layouttitlebar->addWidget(titlebar);
ui.widget_tiltebar->setLayout(layouttitlebar);
Maintain *maintain = new Maintain(this);
QVBoxLayout *layoutmaintain = new QVBoxLayout();
layoutmaintain->addWidget(maintain);
ui.widget_maintain->setLayout(layoutmaintain);
FunctionWidget *function = new FunctionWidget(this);
QVBoxLayout *layoutfunction = new QVBoxLayout();
layoutfunction->addWidget(function);
ui.widget_function->setLayout(layoutfunction);
DataShow *datashow = new DataShow(this);
QVBoxLayout *layoutdatashow = new QVBoxLayout();
layoutdatashow->addWidget(datashow);
ui.widget_dataview->setLayout(layoutdatashow);
MaterialInfo *materinfo = new MaterialInfo(this);
QVBoxLayout *layoutmaterinfo = new QVBoxLayout();
layoutmaterinfo->addWidget(materinfo);
ui.widget_info->setLayout(layoutmaterinfo);
ChartA *charta = new ChartA(this);
QVBoxLayout *layoutcharta = new QVBoxLayout();
layoutcharta->addWidget(charta);
ui.widget_a->setLayout(layoutcharta);
ChartB *chartb = new ChartB(this);
QVBoxLayout *layoutchartb = new QVBoxLayout();
layoutchartb->addWidget(chartb);
ui.widget_b->setLayout(layoutchartb);
ChartC *chartc = new ChartC(this);
QVBoxLayout *layoutchartc = new QVBoxLayout();
layoutchartc->addWidget(chartc);
ui.widget_c->setLayout(layoutchartc);
ChartD *chartd = new ChartD(this);
QVBoxLayout *layoutchartd = new QVBoxLayout();
layoutchartd->addWidget(chartd);
ui.widget_d->setLayout(layoutchartd);
ChartE *charte = new ChartE(this);
QVBoxLayout *layoutcharte = new QVBoxLayout();
layoutcharte->addWidget(charte);
ui.widget_e->setLayout(layoutcharte);
ChartF *chartf = new ChartF(this);
QVBoxLayout *layoutchartf = new QVBoxLayout();
layoutchartf->addWidget(chartf);
ui.widget_f->setLayout(layoutchartf);
}
void AutoFlawDetection::paintEvent(QPaintEvent * event)
{
QWidget::paintEvent(event);
QPainter painter(this);
painter.drawPixmap(rect(), QPixmap(":/Img/Img/backgroud.jpg"), QRect());
}
在主界面分别绘制widget,添加各个组件或者提升widget为窗口部件。
主界面布局如下:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5d18aca7b4b598226357f0e76d2a3d45.png)
四、效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d2e9a3351eb2c93d90c2d22b6f878993.png)
这样一个界面布局完成,就可以开始写功能了。