求助关于QGraphicsItem的极坐标系对称问题问题

关于QGraphicsItem解决方案 - QT开发&&&&>>&& 关于QGraphicsItemmyitem.h
#ifndef&MYITEM_H
#define&MYITEM_H
#include&&QGraphicsItem&
#include&&QPainter&
class&MyItem&:&public&QGraphicsItem
&&&&Q_OBJECT
&&&&MyItem(QObject&*parent&=&0);
&&&&~MyItem();
protected:
&&&&QRectF&boundingRect()&
&&&&void&paint(QPainter&*,const&QStyleOptionGraphicsItem&*,QWidget&*);
#endif&//&MYITEM_H
myitem.cpp
#include&"myitem.h"
MyItem::MyItem(QObject&*parent)&:
&&&&QGraphicsItem(parent)&&&&&&&&&&&&&&&&&&//这里总是报错:no&matching&function&for&call&to&'QGraphicsItem::QGraphicsItem(QObject*&),求解
MyItem::~MyItem()
QRectF&MyItem::boundingRect()&const
&&&&qreal&penWidth=1;
&&&&return&QRectF(0-penWidth/2,0-penWidth/2,20+penWidth,20+penWidth);
void&MyItem::paint(QPainter&*painter,&const&QStyleOptionGraphicsItem&*,&QWidget&*)
&&&&painter-&setBrush(Qt::red);
&&&&painter-&drawRect(0,0,20,20);
#include&&QApplication&
#include&&QGraphicsScene&
#include&&QGraphicsRectItem&
#include&&QGraphicsView&
#include&&QDebug&
#include&"myitem.h"
int&main(int&argc,char&*argv[])
&&&&QApplication&app(argc,argv);
&&&&QTransform&transF
&&&&QGraphicsScene&
&&&&MyItem&*item=new&MyI
&&&&scene.addItem(item);
&&&&//qDebug()&&scene.itemAt(50,50,transForm)&&
&&&&QGraphicsView&view(&scene);
&&&&view.setForegroundBrush(QBrush(QColor(255,255,255,100)));
&&&&view.setBackgroundBrush(QBrush(QPixmap(":/green.jpg")));
&&&&view.resize(400,300);
&&&&view.show();
&&&&return&app.exec();
&------解决方案--------------------引用:Quote: 引用:
Quote: 引用:
Quote: 引用:
你的类型声明错了吧:
class&MyItem&:&public&QGraphicsItem
&&&&Q_OBJECT
&&&&MyItem(QObject&*parent&=&0);
&&&&~MyItem();
protected:
&&&&QRectF&boundingRect()&
&&&&void&paint(QPainter&*,const&QStyleOptionGraphicsItem&*,QWidget&*);
这个MyItem构造函数的参数不是QObject,应该是QW
还是不行啊,报错:no&matching&function&for&call&to&'QGraphicsItem::QGraphicsItem(QWidget*&)
不好意思哈,那个构造函数的参数类型是QGraphicsItem
改成这样:
class&MyItem&:&public&QGraphicsItem
&&&&Q_OBJECT
&&&&explicit&MyItem(QGraphicsItem&*parent&=&0);
&&&&~MyItem();
protected:
&&&&QRectF&boundingRect()&
&&&&void&paint(QPainter&*,const&QStyleOptionGraphicsItem&*,QWidget&*);
MyItem::MyItem(QGraphicsItem&*parent)&:
&&&&QGraphicsItem(parent)
可是这样错误更多了
是的,你看你这里函数声明:
&&&&void&paint(QPainter&*,const&QStyleOptionGraphicsItem&*,QWidget&*);
再看看你的函数定义:
void&MyItem::paint(QPainter&*painter,&const&QStyleOptionGraphicsItem&*,&QWidget&*)
&&&&painter-&setBrush(Qt::red);
&&&&painter-&drawRect(0,0,20,20);
你应该把函数这样声明:
&&&&void&paint(QPainter&*painter,const&QStyleOptionGraphicsItem&*,QWidget&*);2011年10月 移动平台大版内专家分月排行榜第三2010年11月 移动平台大版内专家分月排行榜第三
2011年10月 移动平台大版内专家分月排行榜第三2010年11月 移动平台大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。qgraphicsitem_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
qgraphicsitem
你可能喜欢2012年9月 移动平台大版内专家分月排行榜第二
2012年11月 移动平台大版内专家分月排行榜第三
2012年9月 移动平台大版内专家分月排行榜第二
2012年11月 移动平台大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 坐标关于原点对称 的文章

 

随机推荐