資源簡介
基于Qt QGraphicsScene的畫圖演示,可對圖元進行移動和縮放,例子比較簡單,可以參考。

代碼片段和文件信息
#include?“eresizefocus.h“
#include?“svgscene.h“
#include?“SvgGraphicsItem.h“
#include?
EResizeFocus::EResizeFocus(PosInHost?posSvgGraphicsItem?*svgitem)
:?QGraphicsRectItem(0066)posInHost(pos)wsize(6)
{
/*SvgScene::myscene->addItem(this);
setAcceptsHoverEvents(true);
setVisible(false);
QPen?pen?=?QPen(QColor(Qt::blue));
setPen(pen);
QBrush?brush?=?QBrush(QColor(Qt::red));
setBrush(brush);*/
mySvgItem?=?svgitem;
initial();
//locateInHost();
}
EResizeFocus::~EResizeFocus()
{
}
void?EResizeFocus::initial(){
SvgScene::myscene->addItem(this);
setAcceptsHoverEvents(true);
setVisible(false);
QPen?pen?=?QPen(QColor(Qt::blue));
setPen(pen);
QBrush?brush?=?QBrush(QColor(Qt::red));
setBrush(brush);
locateInHost();
}
void?EResizeFocus::hoverEnterEvent?(?QGraphicsSceneHoverEvent?*?event?)
{
switch(posInHost){
case?NORTH_MIDDLE:
setCursor(Qt::SizeVerCursor);
break;
case?SOUTH_MIDDLE:
setCursor(Qt::SizeVerCursor);
break;
case?EAST_MIDDLE:
setCursor(Qt::SizeHorCursor);
break;
case?WEST_MIDDLE:
setCursor(Qt::SizeHorCursor);
break;
case?NORTH_WEST:
setCursor(Qt::SizeFDiagCursor);
break;
case?SOUTH_EAST:
setCursor(Qt::SizeFDiagCursor);
break;
case?NORTH_EAST:
setCursor(Qt::SizeBDiagCursor);
break;
case?SOUTH_WEST:
setCursor(Qt::SizeBDiagCursor);
break;
default:
break;
}
QGraphicsRectItem::hoverEnterEvent(event);
}
void?EResizeFocus::hoverLeaveEvent?(?QGraphicsSceneHoverEvent?*?event?)
{
QGraphicsRectItem::hoverLeaveEvent(event);
}
void?EResizeFocus::locateInHost()
{
const?QRectF?parentRect?=?mySvgItem->matrixBoundingRect();
qreal?x?=?0?y?=?0;
switch(posInHost){
case?NORTH_MIDDLE:
x?=?parentRect.x()?+?parentRect.width()?/?2?-?wsize?/?2;
y?=?parentRect.y()-?wsize?/?2;
break;
case?SOUTH_MIDDLE:
x?=?parentRect.x()?+?parentRect.width()?/?2?-?wsize?/?2;
y?=?parentRect.y()?+parentRect.height()?-?wsize/2;
break;
case?EAST_MIDDLE:
x?=?parentRect.x()?+?parentRect.width()?-?wsize/2;
y?=?parentRect.y()?+?parentRect.height()?/?2?-?wsize?/?2;
break;
case?WEST_MIDDLE:
x?=?parentRect.x()-?wsize?/?2;
y?=?parentRect.y()+?parentRect.height()?/?2?-?wsize?/?2;
break;
case?NORTH_WEST:
x?=?parentRect.x()-?wsize?/?2;
y?=?parentRect.y()-?wsize?/?2;
break;
case?SOUTH_EAST:
x?=?parentRect.x()?+?parentRect.width()?-?wsize/2;
y?=?parentRect.y()?+?parentRect.height()?-?wsize/2;
break;
case?NORTH_EAST:
x?=?parentRect.x()?+?parentRect.width()?-?wsize/2;
y?=?parentRect.y()-?wsize?/?2;
break;
case?SOUTH_WEST:
x?=?parentRect.x()-?wsize?/?2;
y?=?parentRect.y()?+?parentRect.height()?-?wsize/2;
break;
default:
break;
}
setPos(xy);
}
const?EResizeFocus?&EResizeFocus::operator=(const?EResizeFocus?&?right?)
{
wsize?=?right.wsize;
return?*this;
}
void?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????131072??2010-11-10?15:54??畫圖調節大小源代碼\Debug\MainWindowTest.exe
?????文件????1320224??2010-11-10?15:54??畫圖調節大小源代碼\Debug\MainWindowTest.ilk
?????文件????2427904??2010-11-10?15:54??畫圖調節大小源代碼\Debug\MainWindowTest.pdb
?????文件??????15614??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\BuildLog.htm
?????文件?????157118??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\eresizefocus.obj
?????文件??????42798??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\main.obj
?????文件????????621??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\MainWindowTest.exe.intermediate.manifest
?????文件?????185737??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\mainwindowtest.obj
?????文件??????44236??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\moc_mainwindowtest.obj
?????文件??????49908??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\moc_myitemproxywidget.obj
?????文件?????????67??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\mt.dep
?????文件?????168409??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\myitemproxywidget.obj
?????文件??????23085??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\qrc_mainwindowtest.obj
?????文件?????156947??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\svgellipseitem.obj
?????文件??????70227??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\svggraphicsitem.obj
?????文件?????156517??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\svgrectitem.obj
?????文件?????138823??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\svgscene.obj
?????文件?????133002??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\svgview.obj
?????文件????1977344??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\vc90.idb
?????文件????1757184??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\Debug\vc90.pdb
?????文件???????5891??2009-12-30?08:39??畫圖調節大小源代碼\MainWindowTest\eresizefocus.cpp
?????文件???????1258??2009-12-29?21:13??畫圖調節大小源代碼\MainWindowTest\eresizefocus.h
?????文件???????2462??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\GeneratedFiles\Debug\moc_mainwindowtest.cpp
?????文件???????2405??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\GeneratedFiles\Debug\moc_myitemproxywidget.cpp
?????文件??????72423??2010-11-10?15:54??畫圖調節大小源代碼\MainWindowTest\GeneratedFiles\qrc_mainwindowtest.cpp
?????文件???????4347??2009-09-12?11:25??畫圖調節大小源代碼\MainWindowTest\GeneratedFiles\ui_mainwindowtest.h
?????文件???????1352??2009-07-14?08:13??畫圖調節大小源代碼\MainWindowTest\GeneratedFiles\ui_table.h
?????文件???????1339??2008-01-09?08:43??畫圖調節大小源代碼\MainWindowTest\images\copy.png
?????文件???????1323??2008-01-09?08:43??畫圖調節大小源代碼\MainWindowTest\images\cut.png
?????文件???????2011??2008-01-09?08:43??畫圖調節大小源代碼\MainWindowTest\images\find.png
............此處省略51個文件信息
評論
共有 條評論