使用Qt实现的C++画板(包含源码,可执行exe文件)

上传者: realliyuhao | 上传时间: 2022-05-07 17:19:03 | 文件大小: 18.73MB | 文件类型: ZIP
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // 给pixmap赋值 pixmap = new QPixmap(900, 600); //设置背景色 pixmap->fill(Qt::white); //根据pixmap创建一个qpaiter painter= new QPainter(pixmap); // 使用 pixmap,也就是把这个控件加到ui里面 ui->pixmap_label->setPixmap(*pixmap); //这里关联信号和槽 connect(ui->linecolor_r_slider,SIGNAL(valueChanged(int)),this,SLOT(linecolor_changed())); connect(ui->linecolor_g_slider,SIGNAL(valueChanged(int)),this,SLOT(linecolor_changed())); connect(ui->linecolor_b_slider,SIGNAL(valueChanged(int)),this,SLOT(linecolor_changed())); connect(ui->fillcolor_comboBox,SIGNAL(currentTextChanged(QString)),this,SLOT(fillcolor_changed())); //这里初始化填充颜色下拉框: ui->fillcolor_comboBox->addItem("黑色"); ui->fillcolor_comboBox->addItem("白色"); ui->fillcolor_comboBox->addItem("红色"); ui->fillcolor_comboBox->addItem("绿色"); ui->fillcolor_comboBox->addItem("蓝色"); ui->fillcolor_comboBox->addItem("黄色"); } MainWindow::~MainWindow() { delete ui; delete pixmap; delete painter; delete linecolor;delete fillcolor; delete circle,rect; } //这个函数是生成按钮被按下时的画图实现: void MainWindow::on_draw_button_clicked() { if (ui->tabWidget->currentIndex()==0)//这个是画圆的部分 { circle =new Circle(new QPoint(ui->circle_x_spinBox->value(),ui->circle_y_spinBox->value()),ui->circle_r_spinBox->value()); circle->draw(painter); } else if (ui->tabWidget->currentIndex()==1){ rect=new Rect(new QPoint(ui->rect_x_spinBox->value(),ui->rect_y_spinBox->value()),ui->rect_a_spinBox->value(),ui->rect_b_spinBox->value()); rect->draw(painter); } ui->pixmap_label->setPixmap(*pixmap); } //这个函数就是设置边线颜色的: void MainWindow::linecolor_changed(){ linecolor=new QColor(ui->linecolor_r_slider->value(),ui->linecolor_g_slider->value(),ui->linecolor_b_slider->value()); painter->setPen(*linecolor); QPalette label_palette; label_palette.setColor(QPalette::Background, *linecolor); ui->linecolor_display_label->setAutoFillBackground(true); ui->linecolor_display_label->setPalette(label_palette); } void MainWindow::fillcolor_changed(){ QString str=ui->fillcolor_comboBox->currentText(); if (str=="黑色"){ fillcolor =new QColor(Qt::black); } else if (str=="蓝色"){ fillcolor =new QColor(Qt::blue); } else if (str=="黄色"){ fillcolor =new QColor(Qt::yellow); } else if (str=="白色"){ fillcolor =new QColor(Qt::white); } else if (str=="绿色"){ fillcolor =new QColor(Qt::green); } else if (str=="红色"){ fillcolor =new QColor(Qt::red); } painter->setBrush(QBrush(*fillcolor)); } //这个函数一不小心搞出来,没用,删了会报错? void MainWindow::on_linecolor_r_slider_actionTriggered(int action) { } //这个函数就是用来保存的功能实现: void MainWindow::on_save_button_clicked() { ofstream out("D://data.txt", ios::out|ios::app); if (ui->tabWidget->currentIndex()==0)//此处保存圆 { out<<"circle"<center->x()<<" "<center->y()<<" "<r<tabWidget->currentIndex()==1)//此处保存矩形 { out<<"rect"<northeast->x()<<" "<northeast->y()<<" "<width<<" "<height<<" "<red()<<" "<green()<<" "<blue()<<" "<red()<<" "<green()<<" "<blue()<<" "<>str){ if (str=="rect"){ infile>>z>>a>>b>>c>>d; rect = new Rect(new QPoint(a,b),c,d); infile>>a>>b>>c; linecolor=new QColor(a,b,c); painter->setPen(*linecolor); infile>>a>>b>>c; fillcolor=new QColor(a,b,c); painter->setBrush(QBrush(*fillcolor)); rect->draw(painter); } else{ infile>>z>>a>>b>>c; circle=new Circle(new QPoint(a,b),c); infile>>a>>b>>c; linecolor=new QColor(a,b,c); painter->setPen(*linecolor); infile>>a>>b>>c; fillcolor=new QColor(a,b,c); painter->setBrush(QBrush(*fillcolor)); circle->draw(painter); } ui->pixmap_label->setPixmap(*pixmap); } infile.close();} void MainWindow::on_clear_button_clicked() { pixmap->fill(Qt::white); ui->pixmap_label->setPixmap(*pixmap); }

文件下载

资源详情

[{"title":"( 65 个子文件 18.73MB ) 使用Qt实现的C++画板(包含源码,可执行exe文件)","children":[{"title":"C++画板","children":[{"title":"src","children":[{"title":"mainwindow.ui <span style='color:#111;'> 13.99KB </span>","children":null,"spread":false},{"title":"Lab3.pro.user <span style='color:#111;'> 23.28KB </span>","children":null,"spread":false},{"title":"circle.h <span style='color:#111;'> 269B </span>","children":null,"spread":false},{"title":"circle.cpp <span style='color:#111;'> 315B </span>","children":null,"spread":false},{"title":"mainwindow.cpp <span style='color:#111;'> 5.32KB </span>","children":null,"spread":false},{"title":"rect.h <span style='color:#111;'> 304B </span>","children":null,"spread":false},{"title":"main.cpp <span style='color:#111;'> 183B </span>","children":null,"spread":false},{"title":"rect.cpp <span style='color:#111;'> 244B </span>","children":null,"spread":false},{"title":"shape.h <span style='color:#111;'> 162B </span>","children":null,"spread":false},{"title":"Lab3.pro <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false},{"title":"mainwindow.h <span style='color:#111;'> 1.17KB </span>","children":null,"spread":false},{"title":"shape.cpp <span style='color:#111;'> 67B </span>","children":null,"spread":false}],"spread":false},{"title":"exe所在目录","children":[{"title":"Qt5Svg.dll <span style='color:#111;'> 351.50KB </span>","children":null,"spread":false},{"title":"libGLESV2.dll <span style='color:#111;'> 2.68MB </span>","children":null,"spread":false},{"title":"moc_mainwindow.cpp <span style='color:#111;'> 4.78KB </span>","children":null,"spread":false},{"title":"main.o <span style='color:#111;'> 1.44KB </span>","children":null,"spread":false},{"title":"Qt5Widgets.dll <span style='color:#111;'> 6.06MB </span>","children":null,"spread":false},{"title":"iconengines","children":[{"title":"qsvgicon.dll <span style='color:#111;'> 42.00KB </span>","children":null,"spread":false}],"spread":true},{"title":"libwinpthread-1.dll <span style='color:#111;'> 77.50KB </span>","children":null,"spread":false},{"title":"Qt5Gui.dll <span style='color:#111;'> 5.92MB </span>","children":null,"spread":false},{"title":"Qt5Core.dll <span style='color:#111;'> 5.81MB </span>","children":null,"spread":false},{"title":"circle.o <span style='color:#111;'> 2.24KB </span>","children":null,"spread":false},{"title":"mainwindow.o <span style='color:#111;'> 57.41KB </span>","children":null,"spread":false},{"title":"Lab3.exe <span style='color:#111;'> 56.00KB </span>","children":null,"spread":false},{"title":"moc_predefs.h <span style='color:#111;'> 9.66KB </span>","children":null,"spread":false},{"title":"libgcc_s_dw2-1.dll <span style='color:#111;'> 117.51KB </span>","children":null,"spread":false},{"title":"libEGL.dll <span style='color:#111;'> 21.50KB </span>","children":null,"spread":false},{"title":"moc_mainwindow.o <span style='color:#111;'> 9.91KB </span>","children":null,"spread":false},{"title":"platforms","children":[{"title":"qwindows.dll <span style='color:#111;'> 1.67MB </span>","children":null,"spread":false}],"spread":false},{"title":"shape.o <span style='color:#111;'> 1.32KB </span>","children":null,"spread":false},{"title":"opengl32sw.dll <span style='color:#111;'> 15.25MB </span>","children":null,"spread":false},{"title":"Lab3.exe - 快捷方式.lnk <span style='color:#111;'> 739B </span>","children":null,"spread":false},{"title":"D3Dcompiler_47.dll <span style='color:#111;'> 3.52MB </span>","children":null,"spread":false},{"title":"translations","children":[{"title":"qt_fi.qm <span style='color:#111;'> 157.25KB </span>","children":null,"spread":false},{"title":"qt_cs.qm <span style='color:#111;'> 170.60KB </span>","children":null,"spread":false},{"title":"qt_ca.qm <span style='color:#111;'> 175.01KB </span>","children":null,"spread":false},{"title":"qt_es.qm <span style='color:#111;'> 161.29KB </span>","children":null,"spread":false},{"title":"qt_gd.qm <span style='color:#111;'> 169.50KB </span>","children":null,"spread":false},{"title":"qt_lv.qm <span style='color:#111;'> 150.00KB </span>","children":null,"spread":false},{"title":"qt_uk.qm <span style='color:#111;'> 154.52KB </span>","children":null,"spread":false},{"title":"qt_sk.qm <span style='color:#111;'> 122.81KB </span>","children":null,"spread":false},{"title":"qt_pl.qm <span style='color:#111;'> 159.15KB </span>","children":null,"spread":false},{"title":"qt_hu.qm <span style='color:#111;'> 88.86KB </span>","children":null,"spread":false},{"title":"qt_ru.qm <span style='color:#111;'> 154.14KB </span>","children":null,"spread":false},{"title":"qt_en.qm <span style='color:#111;'> 23B </span>","children":null,"spread":false},{"title":"qt_it.qm <span style='color:#111;'> 157.35KB </span>","children":null,"spread":false},{"title":"qt_da.qm <span style='color:#111;'> 165.68KB </span>","children":null,"spread":false},{"title":"qt_de.qm <span style='color:#111;'> 183.58KB </span>","children":null,"spread":false},{"title":"qt_fr.qm <span style='color:#111;'> 162.26KB </span>","children":null,"spread":false},{"title":"qt_he.qm <span style='color:#111;'> 135.43KB </span>","children":null,"spread":false},{"title":"qt_bg.qm <span style='color:#111;'> 161.45KB </span>","children":null,"spread":false},{"title":"qt_ja.qm <span style='color:#111;'> 126.86KB </span>","children":null,"spread":false},{"title":"qt_ko.qm <span style='color:#111;'> 128.18KB </span>","children":null,"spread":false}],"spread":false},{"title":"libstdc++-6.dll <span style='color:#111;'> 1.47MB </span>","children":null,"spread":false},{"title":"imageformats","children":[{"title":"qtga.dll <span style='color:#111;'> 26.00KB </span>","children":null,"spread":false},{"title":"qgif.dll <span style='color:#111;'> 33.00KB </span>","children":null,"spread":false},{"title":"qwebp.dll <span style='color:#111;'> 438.50KB </span>","children":null,"spread":false},{"title":"qtiff.dll <span style='color:#111;'> 437.50KB </span>","children":null,"spread":false},{"title":"qwbmp.dll <span style='color:#111;'> 25.00KB </span>","children":null,"spread":false},{"title":"qsvg.dll <span style='color:#111;'> 26.50KB </span>","children":null,"spread":false},{"title":"qicns.dll <span style='color:#111;'> 45.50KB </span>","children":null,"spread":false},{"title":"qjpeg.dll <span style='color:#111;'> 242.00KB </span>","children":null,"spread":false},{"title":"qico.dll <span style='color:#111;'> 35.50KB </span>","children":null,"spread":false}],"spread":false},{"title":"rect.o <span style='color:#111;'> 2.22KB </span>","children":null,"spread":false}],"spread":false},{"title":"Lab3.exe - 快捷方式.lnk <span style='color:#111;'> 804B </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明