• 大小: 0.17M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-02-22
  • 语言: C/C++
  • 标签: 旋转  Qt  拉伸  

资源简介

 if(isSelected())
 {
 if(m_dir == Right && (event->buttons() & Qt::RightButton)){
 double ang = 0;
 double x = m_cenPt.x()-m_movePoint.x();
 double y = m_cenPt.y()-m_movePoint.y();
 if(abs(x) > 0.001){
 if(x < 0){
 ang = atan(y/x)*180/PI; //通过弧度求角度
 if(ang < 0)
 ang = atan(y/x)*180/PI 360; //通过弧度求角度
 }
 else
 ang = atan(y/x)*180/PI 180; //通过弧度求角度
 }
 double oldAng = rotation();
 setTransformOriginPoint(m_cenPt); //设置旋转中心
 setRotation(ang oldAng); //旋转角度,如果不加oldAng,则角度旋转不对

 }
 else if(m_selectMod == SizeMode){
 resizeTo(m_dir,event->scenePos());
 }
 else
 QGraphicsItem::mouseMoveEvent(event); //如果在拉伸时也调用,则会位置设置不对
 }

资源截图

代码片段和文件信息

#include “graphicscircleitem.h“
#include 
#include 
#include 
#include 
#include 

GraphicsCircleItem::GraphicsCircleItem(const QRect &rect QGraphicsItem *parent) :
    QGraphicsItem(parent)
{
    m_rect       = rect;
    m_radius     = rect.width()/2;
    m_dir        = Center;
    m_selectMod  = NoMode;
    m_pressPoint = QPointF();
    setFlags(QGraphicsItem::ItemIsSelectable |
             QGraphicsItem::ItemSendsGeometryChanges |
             QGraphicsItem::ItemIsFocusable |
             QGraphicsItem::ItemIsMovable);
    setAcceptHoverEvents(true);
}

QRectF GraphicsCircleItem::rect() const
{
    qreal adjust = 2;
    return QRectF(QPointF(m_rect.left()-adjustm_rect.top()-adjust)
                  QPointF(m_rect.right()+adjustm_rect.bottom()+adjust));
}

QRectF GraphicsCircleItem::boundingRect() const
{
    return rect();
}

void GraphicsCircleItem::paint(QPainter *painter const QstyleOptionGraph

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7740  2019-11-07 19:06  testGraphicsView\graphicscircleitem.cpp

     文件       1599  2019-11-07 09:32  testGraphicsView\graphicscircleitem.h

     文件       7695  2019-11-07 19:28  testGraphicsView\graphicsellipseitem.cpp

     文件       1714  2019-11-07 19:06  testGraphicsView\graphicsellipseitem.h

     文件       8128  2019-11-07 19:28  testGraphicsView\graphicsrectitem.cpp

     文件       1744  2019-11-07 19:06  testGraphicsView\graphicsrectitem.h

     文件       2695  2019-11-07 15:45  testGraphicsView\graphicsscene.cpp

     文件        748  2019-11-07 13:28  testGraphicsView\graphicsscene.h

     文件       1358  2019-11-07 18:18  testGraphicsView\graphicsview.cpp

     文件        369  2019-11-07 17:42  testGraphicsView\graphicsview.h

     文件     158112  2019-03-19 12:45  testGraphicsView\img.jpg

     文件        183  2019-11-06 10:21  testGraphicsView\main.cpp

     文件       1549  2019-11-07 15:25  testGraphicsView\mainwindow.cpp

     文件        714  2019-11-07 14:40  testGraphicsView\mainwindow.h

     文件       3604  2019-11-07 11:37  testGraphicsView\mainwindow.ui

     文件        467  2019-11-07 17:41  testGraphicsView\mydef.h

     文件       1578  2019-11-07 11:10  testGraphicsView\testGraphicsView.pro

     文件      46083  2019-11-07 19:36  testGraphicsView\testGraphicsView.pro.user

     目录          0  2019-11-07 19:36  testGraphicsView

----------- ---------  ---------- -----  ----

               246080                    19


评论

共有 条评论