qt画图实验报告doc

  • 格式:docx
  • 大小:15.49 KB
  • 文档页数:20

下载文档原格式

  / 20
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

qt画图实验报告

篇一:QT综合作业实验报告

一、实验目的

1,了解并掌握Qt集成开发环境下使用Qt Designer 开发图形界面程序的流程和相关

操作;

2,了解并掌握Qt的信号槽和信号传递机制,并通过具体应用加深理解;

3,了解并掌握使Qt应用程序支持中文或国际化的方法,并在本次实验中使用; 4,了解并掌握QPainter的translate、shear等库函数的使用方法和Widget类的使用方法,并通过本次实验加深理解;

5,掌握在Qt Designer界面上为菜单项添加工具栏按钮、创建相应槽函数的方法; 6,了解并掌握使用双缓冲机制绘图的方法。

二、实验环境

操作系统:Windows 7

应用软件:Qt Creator

开发平台:qt-sdk-win-opensource-XX.04

三、程序流程图

:

四、核心源代码

mainwindow.cpp的内容(实现菜单项的功能和绘图功能的调用)

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include "donewdialog.h"

#include

#include

#include

#include "aboutdialog.h"

MainWindow::MainWindow(QWidget *parent) :

QMainWindow(parent),

ui(new Ui::MainWindow)

{

ui->setupUi(this);

setWindowTitle(tr("Qt绘图板"));

setFixedSize(700,500); //主窗口大小设为700*500

area = new PaintArea;

scrollArea = new QScrollArea;

scrollArea->setBackgroundRole(QPalette::Dark); //scrollArea对象的背景色设为Dark scrollArea->setWidget(area); //将画布添加到scrollArea中

scrollArea->widget()->setMinimumSize(800,600); //scrollArea初始化大小设为800*600

ui->dockWidget->hide();

setCentralWidget(scrollArea); //将scrollArea加入到主窗口的中心区

isSaved = false;

curFile = tr("未命名.png");

creatColorComboBox(ui->penColorComboBox); //画笔颜色组合框

creatColorComboBox(ui->brushColorComboBox); //填充颜色组合框

}

MainWindow::~MainWindow()

{

delete ui;

}

void MainWindow::changeEvent(QEvent *e)

{

QMainWindow::changeEvent(e);

switch (e->type()) {

case QEvent::LanguageChange:

ui->retranslateUi(this);

break;

default:

break;

}

void MainWindow::doOpen()

{

if (maybeSave())

{

QString fileName = QFileDialog::getOpenFileName(this,

tr("打开文件"), QDir::currentPath());

if (!fileName.isEmpty())

{

area->openImage(fileName);

scrollArea->widget()->resize(area->getImageSize());

//获得图片的大小,然后更改scrollArea的大小

isSaved = true;

curFile = fileName;

}

}

void MainWindow::doNew()

{

if(maybeSave())

{

DoNewDialog dlg;

if(dlg.exec() == QDialog::Accepted)

{

int width = dlg.getWidth();

int height = dlg.getHeight();

area->setImageSize(width,height); scrollArea->widget()->resize(width,height); area->setImageColor(dlg.getBackColor()); isSaved = false;

}

}

bool MainWindow::maybeSave()

{

if(area->isModified())

{

QMessageBox::StandardButton box;

box = QMessageBox::warning(this,tr("保存文件"),tr("图片已经改变,是否保存?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cance l);

if(box == QMessageBox::Yes)

{

return doFileSave();

}

else if(box == QMessageBox::Cancel)

{

return false;

}