【Qt5开发及实例】14、实现一个简单的文本编辑器3

实现文本编辑器的图片旋转功能

基础界面实现:http://blog.csdn.net/cutter_point/article/details/42839071

首先在原来的基础上添加槽函数:

  void ShowRotate90();    //旋转90度
  void ShowRotate180();   //180度
  void ShowRotate270();   //270度

函数连接:

  //实现图片的选择动作
  //旋转90°
  rotate90Action = new QAction(QIcon(":/rotate90.png"), tr("get rotate90"), this);
  rotate90Action->setStatusTip(tr("get rotate90 image"));
  connect(rotate90Action, SIGNAL(triggered()), this, SLOT(ShowRotate90()));
  //180°
  rotate180Action = new QAction(QIcon(":/rotate180.png"), tr("get rotate180"), this);
  rotate180Action->setStatusTip(tr("get rotate180 image"));
  connect(rotate180Action, SIGNAL(triggered()), this, SLOT(ShowRotate180()));
  //270°
  rotate270Action = new QAction(QIcon(":/rotate270.png"), tr("get rotate270"), this);
  rotate270Action->setStatusTip(tr("get rotate270 image"));
  connect(rotate270Action, SIGNAL(triggered()), this, SLOT(ShowRotate270()));

槽函数的具体实现:

//旋转270度
void ImageProcessor::ShowRotate270()
{
  if(img.isNull())
    return;
  QMatrix matrix;
  matrix.rotate(270);    //旋转90度
  img = img.transformed(matrix);    //图像旋转之后再重新得到赋值
  showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}

//旋转180度
void ImageProcessor::ShowRotate180()
{
  if(img.isNull())
    return;
  QMatrix matrix;
  matrix.rotate(180);    //旋转90度
  img = img.transformed(matrix);    //图像旋转之后再重新得到赋值
  showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}

//旋转90度
void ImageProcessor::ShowRotate90()
{
  if(img.isNull())
    return;
  QMatrix matrix;
  matrix.rotate(90);    //旋转90度
  img = img.transformed(matrix);    //图像旋转之后再重新得到赋值
  showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}

实现结果:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值