資源簡介
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
- 上一篇:真彩工具條
- 下一篇:MFC圖片操作(PRO5_PNGDlg.cpp)
評論
共有 條評論