当前位置: 首页 > news >正文

怎么用阿里的域名 做网站什么是seo优化?

怎么用阿里的域名 做网站,什么是seo优化?,上海个人建站模板,贵州网站制作哪家好1. 事件和函数 主要使用事件paintEvent(QPaintEvent *event)和drawTiledPixmap函数实现绘图。 paintEvent事件在改变窗口大小、移动窗口、手动调用update等情形下会被调用。需先了解下绘图该函数的用法。 - QPainter::drawTiledPixmap(int x, int y, int w, int h, const QPi…

1. 事件和函数

主要使用事件paintEvent(QPaintEvent *event)和drawTiledPixmap函数实现绘图。

  1. paintEvent事件在改变窗口大小、移动窗口、手动调用update等情形下会被调用。
  2. 需先了解下绘图该函数的用法。 - QPainter::drawTiledPixmap(int x, int y, int w, int h, const QPixmap &pm, int sx, int sy)
  3. 效果:

2. 建立项目

假设已新建了mainwindow项目。现再添加一界面用于单独显示图片,作为子窗口供调用(当然,也可在main.c直接调用,作为父窗口)。
1)右击界面文件—添加新文件—QT—QT设计师界面类—choose—Dialog without buttons。类名为CImgPaint。
打开ui文件,添加控件,主要是label和button,

具体属性列表如下:

其中,label控件仅仅是提供绘图的区域,但最终绘图不是绘在label控件上。

3. 头文件添加变量,编写构造函数

头文件中包含头文件

#define USE_OPENCV 0#include <QDialog>
#include "mainwindow.h"
#include "QPoint"
using namespace std;
#if USE_OPENCV#include "opencv2/opencv.hpp"#include <opencv2/core.hpp>using namespace cv;
#endifnamespace Ui {
class CImgPaint;
}
类中添加成员变量
private:QPixmap  pix_src,pix_fix;//原始图片及缩放图片float ratio=1.0;        //缩放比QRect paint_rect;           //绘画限制区域int paint_xe,paint_ye,paint_we,paint_he;//期望绘画区域int paint_x,paint_y,paint_w,paint_h;//实际绘画区域int pix_sx,pix_sy;          //选择图片的起始x、y开始绘画int step_val = 20;          //单次移动步长bool mouse_press_flag = false;//鼠标是否按下QPoint mouse_pos_pre,mouse_pos_cur;//记录鼠标位置

 构造函数中,添加输入图片的读取,以及变量初始化。

#include "CImgPaint.h"
#include "ui_cimgpaint.h"
#include "QDebug"
#include "QPainter"
#include "QWheelEvent"
#include "QImage"
CImgPaint::CImgPaint(QWidget *parent) :QDialog(parent),ui(new Ui::CImgPaint)
{ui->setupUi(this);#if USE_OPENCVcv::Mat img = cv::imread("lenaGray.jpg",-1);pix_src = get_pixmap_from_mat(img);
#elseQImage qimg ;qimg.load("./lenaGray.jpg");pix_src = pix_src.fromImage(qimg);
#endifpaint_rect.setRect(ui->label_paint->x()+1,ui->label_paint->y()+1,ui->label_paint->width()+1,ui->label_paint->height()+1);pix_fix = pix_src.scaled(paint_rect.width(),paint_rect.height(),Qt::KeepAspectRatio,Qt::FastTransformation);reset_para();update_para();
}void CImgPaint::reset_para(void)
{ratio = 1.0;paint_xe = paint_x =paint_rect.x()  ;paint_ye = paint_y = paint_rect.y();paint_we = paint_w = paint_rect.width();paint_he = paint_h = paint_rect.height();pix_sx = 0;pix_sy = 0;
}#if USE_OPENCV
QPixmap CImgPaint::get_pixmap_from_mat(Mat img)
{cv::Mat img_temp = img.clone();QImage::Format format = QImage::Format_RGB888;if(img_temp.channels()==1){format  = QImage::Format_Grayscale8;}if(img_temp.channels()==3){cv::cvtColor(img_temp,img_temp,CV_BGR2RGB);//opencv 按BGR处理}if(img_temp.depth()==CV_16U){img_temp.convertTo(img_temp,CV_8U,1.0/257.0);}QPixmap pixmap = QPixmap::fromImage(QImage(img_temp.data,img_temp.cols,img_temp.rows,(int)img_temp.step,format));return pixmap;}
#endif
CImgPaint::~CImgPaint()
{delete ui;
}

update_para函数用来确定drawTiledPixmap函数的各参数。

void CImgPaint::update_para(void)
{//*************** 0. 处理放大和缩小 **********************//// 放大缩小仅仅改变width和height,图像的起始点,不变int w,h;w = ratio*paint_rect.width();//放大或缩小,统一对标到画布尺寸h = ratio*paint_rect.height();pix_fix = pix_src.scaled(w,h,Qt::KeepAspectRatio,Qt::FastTransformation);//对输入的原图进行放大、缩小paint_we = pix_fix.width();//得到初始的图像w、h期望值paint_he = pix_fix.height();//*************** 1. 处理Y方向 **********************////1.1 首先确定实际绘图的起点,绘图的起点应在画布的大小范围内 //// 若期望的起点超出画布上限,则设置截取图像的起始位置sypaint_y = paint_ye;if(paint_y < paint_rect.y()){pix_sy =  paint_rect.y() - paint_y;pix_sy = pix_sy>pix_fix.height()?pix_fix.height():pix_sy;paint_y = paint_rect.y();}else{pix_sy = 0;}//若期望的起点超出画布下限,不允许if(paint_y>=(paint_rect.y()+paint_rect.height()-1)){paint_y = (paint_rect.y()+paint_rect.height()-1);}//1.2 再确定终点,即高度//对于图片本身,减去sy,得到图片本身剩余的高度paint_he -= pix_sy;// 图片本身的高度,同样不可超过画图区域剩余的高度paint_he = paint_he>( paint_rect.height()+paint_rect.y()-paint_y )?(paint_rect.height()+paint_rect.y()-paint_y):paint_he;//*************** 2. 处理X方向 **********************////1.1 首先确定实际绘图的起点,绘图的起点应在画布的大小范围内 //// 若期望的起点超出画布上限,则设置截取图像的起始位置sxpaint_x = paint_xe;if(paint_x < paint_rect.x()){pix_sx =  paint_rect.x() - paint_x;pix_sx = pix_sx>pix_fix.width()?pix_fix.width():pix_sx;paint_x = paint_rect.x();}else{pix_sx = 0;}//若期望的起点超出画布下限,不允许if(paint_x>=(paint_rect.x()+paint_rect.width()-1)){paint_x = (paint_rect.x()+paint_rect.width()-1);}//1.2 再确定终点,即宽度//对于图片本身,减去sx,得到图片本身剩余的宽度paint_we -= pix_sx;// 图片本身的宽度,同样不可超过画图区域剩余的宽度paint_we = paint_we>( paint_rect.width()+paint_rect.x()-paint_x )?(paint_rect.width()+paint_rect.x()-paint_x):paint_we;paint_h = paint_he;paint_w = paint_we;qDebug()<<paint_rect;qDebug()<<paint_x<<paint_y<<paint_w<<paint_h<<pix_fix<<pix_sx<<pix_sy;}

4. paintEvent事件

头文件声明void paintEvent(QPaintEvent *event);并且在cpp文件中重写该事件函数


public slots:void paintEvent(QPaintEvent *event);
void CImgPaint::paintEvent(QPaintEvent *event)
{QPainter painter(this);painter.setRenderHints(QPainter::SmoothPixmapTransform|QPainter::Antialiasing|QPainter::TextAntialiasing);painter.drawRect(paint_rect.x()-1,paint_rect.y()-1,paint_rect.width()+1,paint_rect.height()+1); //画框painter.drawTiledPixmap(paint_x,paint_y,paint_w,paint_h,pix_fix,pix_sx,pix_sy);//绘图}

 5. 编写按钮的回调函数

按钮的回调函数主要用来修改变量的值。修改完后,调用update_para、update,重绘。
update_para函数用来确定drawTiledPixmap函数的各参数。

void CImgPaint::on_pushButton_zoomIn_clicked()
{ratio = ratio + 0.1*ratio;update_para();this->update();
}void CImgPaint::on_pushButton_zoomOut_clicked()
{ratio = ratio - 0.1*ratio;update_para();this->update();
}void CImgPaint::on_pushButton_Up_clicked()
{paint_ye -=step_val;update_para();this->update();
}void CImgPaint::on_pushButton_Down_clicked()
{paint_ye +=step_val;update_para();this->update();}void CImgPaint::on_pushButton_Left_clicked()
{paint_xe -= step_val;update_para();this->update();}void CImgPaint::on_pushButton_Right_clicked()
{paint_xe += step_val;update_para();this->update();}void CImgPaint::on_pushButton_reset_clicked()
{reset_para();update_para();this->update();
}

这样,可以通过点击按钮来完成图片的移动、缩放。

6.鼠标拖动、滚轮实现图片拖动及缩放

重写如下虚函数

public slots:void wheelEvent(QWheelEvent *event);bool event(QEvent *event);void mouseDoubleClickEvent(QMouseEvent *event);
void CImgPaint::mouseDoubleClickEvent(QMouseEvent *event)
{if(event->button()==Qt::LeftButton && paint_rect.contains(event->pos())){reset_para();update_para();this->update();}
}
bool CImgPaint::event(QEvent *event)
{qDebug()<<"event";if(event->type() == QEvent::MouseButtonPress ){QMouseEvent *mouse = dynamic_cast<QMouseEvent* >(event);//QPoint temp = mouse->pos();if(mouse->button()==Qt::LeftButton && paint_rect.contains(mouse->pos())){mouse_press_flag = true;QApplication::setOverrideCursor(Qt::OpenHandCursor);mouse_pos_pre = mouse->pos();}qDebug()<<"MouseButtonPress";}else if(event->type() == QEvent::MouseButtonRelease){QMouseEvent *mouse = dynamic_cast<QMouseEvent* >(event);//判断鼠标是否是左键释放,且之前是在绘画区域if(mouse->button()==Qt::LeftButton && mouse_press_flag ){QApplication::setOverrideCursor(Qt::ArrowCursor); //改回鼠标样式mouse_press_flag=false;}qDebug()<<"MouseButtonRelease";}if(event->type() == QEvent::MouseMove)              //移动图片{if(mouse_press_flag){QMouseEvent *mouse = dynamic_cast<QMouseEvent* >(event);mouse_pos_cur = mouse->pos();int dx = mouse_pos_cur.x() - mouse_pos_pre.x();int dy = mouse_pos_cur.y() - mouse_pos_pre.y();mouse_pos_pre = mouse_pos_cur;paint_xe += dx;paint_ye += dy;update_para();this->update();}qDebug()<<"MouseMove";}return QWidget::event(event);
}void CImgPaint::wheelEvent(QWheelEvent *event)
{if (event->delta()>0) //上滑,缩小{on_pushButton_zoomIn_clicked();}else //下滑,放大{on_pushButton_zoomOut_clicked();}event->accept();
}

可实现鼠标拖动、滚轮的方式来完成图片的拖动、缩放。
源码下载地址(附使用方法):
https://download.csdn.net/download/xiaohuolong1827/78238541

原链接


文章转载自:
http://trichomaniac.c7513.cn
http://unwittingly.c7513.cn
http://obscurantic.c7513.cn
http://shot.c7513.cn
http://ethanolamine.c7513.cn
http://perispomenon.c7513.cn
http://proctorize.c7513.cn
http://backsheesh.c7513.cn
http://regent.c7513.cn
http://soul.c7513.cn
http://meteyard.c7513.cn
http://rct.c7513.cn
http://unredeemable.c7513.cn
http://rm.c7513.cn
http://cac.c7513.cn
http://rtl.c7513.cn
http://posteriorly.c7513.cn
http://stepparent.c7513.cn
http://backhander.c7513.cn
http://alexipharmic.c7513.cn
http://sadie.c7513.cn
http://globelet.c7513.cn
http://faulted.c7513.cn
http://tmo.c7513.cn
http://gleization.c7513.cn
http://wineglass.c7513.cn
http://bayreuth.c7513.cn
http://banker.c7513.cn
http://personkind.c7513.cn
http://promptive.c7513.cn
http://ironwork.c7513.cn
http://unshapen.c7513.cn
http://contrabass.c7513.cn
http://fastigium.c7513.cn
http://innominate.c7513.cn
http://chelicera.c7513.cn
http://zoantharian.c7513.cn
http://significs.c7513.cn
http://praiseworthily.c7513.cn
http://antilysim.c7513.cn
http://integrabel.c7513.cn
http://rylean.c7513.cn
http://altercate.c7513.cn
http://bagel.c7513.cn
http://hydromancer.c7513.cn
http://nevadan.c7513.cn
http://unrighteousness.c7513.cn
http://neuropsychosis.c7513.cn
http://slopwork.c7513.cn
http://radioiodinated.c7513.cn
http://valley.c7513.cn
http://penmanship.c7513.cn
http://without.c7513.cn
http://tzarina.c7513.cn
http://dipstick.c7513.cn
http://circumference.c7513.cn
http://matchbox.c7513.cn
http://shipbreaker.c7513.cn
http://topkhana.c7513.cn
http://doubler.c7513.cn
http://hydrothermally.c7513.cn
http://satirise.c7513.cn
http://delicious.c7513.cn
http://charitably.c7513.cn
http://colugo.c7513.cn
http://weaponry.c7513.cn
http://biogeography.c7513.cn
http://quartz.c7513.cn
http://absorbingly.c7513.cn
http://abu.c7513.cn
http://tussive.c7513.cn
http://habitan.c7513.cn
http://speakerine.c7513.cn
http://unwillingness.c7513.cn
http://viny.c7513.cn
http://coxalgy.c7513.cn
http://smoothhound.c7513.cn
http://hektoliter.c7513.cn
http://typhomalarial.c7513.cn
http://fastidious.c7513.cn
http://renunciate.c7513.cn
http://cataplastic.c7513.cn
http://extant.c7513.cn
http://reporter.c7513.cn
http://eyewash.c7513.cn
http://sidelight.c7513.cn
http://valance.c7513.cn
http://hypanthial.c7513.cn
http://ethically.c7513.cn
http://overlade.c7513.cn
http://qairwan.c7513.cn
http://dunk.c7513.cn
http://lendable.c7513.cn
http://semidilapidation.c7513.cn
http://solidification.c7513.cn
http://spiritualisation.c7513.cn
http://touch.c7513.cn
http://headful.c7513.cn
http://orlop.c7513.cn
http://sonar.c7513.cn
http://www.zhongyajixie.com/news/96940.html

相关文章:

  • 快速搭建网站后台凡科建站登录官网
  • 计算机应用技术网站开发企业营销策划书
  • 宠物网站建设方案外贸网站建设推广公司
  • 嘉兴微信网站建设宁波优化seo软件公司
  • 大型网站怎么做seo痘痘怎么去除效果好
  • 廊坊高端品牌网站建设写一篇软文多少钱
  • 网站 域名 云服务器seo的中文名是什么
  • 网站的跳出率简述网站建设的一般流程
  • 郑州做网站锐刷网站seo排名软件
  • 模板网点地址信息获取错误是什么意思seo黑帽优化
  • 影视广告网站军事新闻最新消息今天
  • 口碑好的唐山网站建设厦门人才网招聘最新信息
  • wordpress 如何添加关键词seoul是韩国哪个城市
  • 微信公众号 做不了微网站无屏蔽搜索引擎
  • 静态网站模版全球搜索
  • wordpress返回404整站seo优化哪家好
  • 做系统用什么网站好石家庄新闻网
  • 肇庆网站设计西安百度seo排名
  • 重庆建设工程造价管理协会网站谷歌浏览器最新版本
  • 百度空间导出wordpress青岛网站优化公司哪家好
  • 翻墙在线代理seo排名优化资源
  • 电子商务网站建设与管理目录外链信息
  • 广州做网站多视频seo优化教程
  • 好看的网站色彩搭配seo推广网址
  • 深圳龙岗房广州网站优化费用
  • 江苏网站建设代理商如何出售自己的域名
  • 优惠券网站做淘客违规吗长尾关键词挖掘爱站工具
  • php购物网站设计代码sem竞价托管价格
  • 做的网站客户拿去维违法有产品怎么找销售渠道
  • wordpress链接分类目录是什么意思优化大师手机版