#include "view.h"
#include <QVBoxLayout>
View::View(QWidget *parent) : QWidget(parent)
{
this->resize(800,600); //设置窗口大小
//设置背景色
QPalette palette(this->palette());
palette.setColor(QPalette::Background, Qt::lightGray);
this->setPalette(palette);
// 创建一个QFont对象,设置字体
label.setFont(QFont("微软雅黑",42,QFont::Bold));
// 设置对齐方式为居中对齐
label.setAlignment(Qt::AlignCenter);
// 设置文本内容
label.setText("Hello MVP!");
// 显示图片
image_label.setScaledContents(true); //show all
image_label.setPixmap(QPixmap("D:/WorkSpace/QT/MvpTest/picture_normal.jpg"));
//设置按钮内容
button.setText("Click me!");
button.setStyleSheet("QPushButton { background-color: white; color: black; }");
button.resize(50,30);
//排版
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(&label);
layout->addWidget(&image_label);
layout->addWidget(&button);
connect(&button, &QPushButton::clicked, this, &View::buttonClicked);
}
void View::update_image(const std::string path)
{
image_label.setScaledContents(true); //show all
image_label.setPixmap(QPixmap(QString::fromStdString(path)));
}
void View::update_message(const std::string data)
{
label.setText(QString::fromStdString(data));
}
void View::buttonClicked()
{
label.setText(QString::fromStdString(model->get_data()));
}
没有合适的资源?快使用搜索试试~ 我知道了~
QT实现Mvp设计模式Demo
共30个文件
sample:13个
cpp:3个
h:3个
需积分: 5 1 下载量 159 浏览量
2023-11-06
11:04:04
上传
评论 1
收藏 87KB ZIP 举报
温馨提示
最近做qt 项目,发现网上基于MVP设计模式的QT例程很少,这里写一个demo示例可作为参考,使用model + View + Interface的方式,每次新增接口只需要在Interface中增加对应接口的虚函数即可。 MVP是由MVC发展而来,总体目的与作用相同。都是为了软件构架有层次之分,使得核心逻辑、界面控制、数据这三者分层清晰明了。减少了三者之间的逻辑耦合与功能耦合。也是的代码清晰易读。从而减少因写代码造成的bug。也增加了软件整体的稳定性。
资源推荐
资源详情
资源评论
收起资源包目录
MvpDemo.zip (30个子文件)
MvpDemo
interface.h 503B
MvpDemo.pro.user 19KB
model.h 578B
view.cpp 1KB
.git
index 656B
HEAD 23B
refs
heads
tags
objects
e6
9de29bb2d1d6434b8b29ae775ad8c2e48c5391 15B
pack
info
description 73B
info
exclude 240B
hooks
post-update.sample 189B
prepare-commit-msg.sample 1KB
commit-msg.sample 896B
pre-receive.sample 544B
update.sample 4KB
pre-commit.sample 2KB
pre-rebase.sample 5KB
applypatch-msg.sample 478B
fsmonitor-watchman.sample 5KB
push-to-checkout.sample 3KB
pre-applypatch.sample 424B
pre-push.sample 1KB
pre-merge-commit.sample 416B
config 130B
main.cpp 175B
picture_blue.jpg 12KB
model.cpp 928B
view.h 606B
picture_normal.jpg 64KB
MvpDemo.pro 620B
.gitignore 814B
共 30 条
- 1
资源评论
我是谁??
- 粉丝: 126
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功