jthacker
1st June 2010, 09:33
hi guys,
i want to zoom particular application icon but can't do can you help me in this..!
i can see the the icon but cant zoom it.
in the zoomTheItem() function i'm getting the x=0 and y=0.
can u help me..!
in the ui file i have put the graphicsView
/*graphicstest2.h*/
#ifndef GRAPHICSTEST2_H
#define GRAPHICSTEST2_H
#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsItem>
namespace Ui {
class GraphicsTest2;
}
class MyQGraphicsScene;
class GraphicsTest2 : public QMainWindow {
Q_OBJECT
public:
GraphicsTest2(QWidget *parent = 0);
~GraphicsTest2();
void zoomTheItem(QGraphicsSceneMouseEvent *event);
void makeItemNormal(QGraphicsSceneMouseEvent *event);
protected:
void changeEvent(QEvent *e);
private:
Ui::GraphicsTest2 *ui;
MyQGraphicsScene *myScene;
QGraphicsPixmapItem *item1;
QGraphicsItem *currentItem;
bool isItemNotScaled;
};
class MyQGraphicsScene :public QGraphicsScene {
Q_OBJECT
public:
MyQGraphicsScene(GraphicsTest2 *parent);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
GraphicsTest2 *myParent;
};
#endif // GRAPHICSTEST2_H
/*graphicstest2.cpp*/
#include "graphicstest2.h"
#include "ui_graphicstest2.h"
GraphicsTest2::GraphicsTest2(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::GraphicsTest2)
{
isItemNotScaled = true;
myScene = new MyQGraphicsScene(this);
myScene->setSceneRect(0,80,800,460);
item1 = new QGraphicsPixmapItem;
item1->setPixmap(QPixmap("./myimages/addressbook.png"));
myScene->addItem(item1);
item1->setPos(50,130);
ui->setupUi(this);
ui->graphicsView->setScene(myScene);
}
GraphicsTest2::~GraphicsTest2()
{
delete ui;
}
void GraphicsTest2::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void GraphicsTest2::zoomTheItem(QGraphicsSceneMouseEven t *event){
printf("\n zoomIn x:%d,y=%d",event->pos().x(),event->pos().y());fflush(stdout);
currentItem = ui->graphicsView->itemAt(event->pos().x(),event->pos().y());
if(!currentItem){
return;
}
if(isItemNotScaled){
currentItem->setScale(1.25);
currentItem->moveBy(-10,-10);
}
isItemNotScaled = false;
}
void GraphicsTest2::makeItemNormal(QGraphicsSceneMouseE vent *event){
if(!isItemNotScaled){
currentItem->setScale(1);
currentItem->moveBy(10,10);
}
isItemNotScaled = true;
printf("\n zoomOut");fflush(stdout);
}
void MyQGraphicsScene::mousePressEvent(QGraphicsSceneMo useEvent *event){
myParent->zoomTheItem(event);
}
void MyQGraphicsScene::mouseReleaseEvent(QGraphicsScene MouseEvent *event){
myParent->makeItemNormal(event);
}
MyQGraphicsScene::MyQGraphicsScene(GraphicsTest2 *parent){
myParent = parent;
}
/*main.cpp*/
#include <QtGui/QApplication>
#include "graphicstest2.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GraphicsTest2 w;
w.show();
return a.exec();
}
note: Qt 4.6.2
Qt Creator 1.3.1
please help
i want to zoom particular application icon but can't do can you help me in this..!
i can see the the icon but cant zoom it.
in the zoomTheItem() function i'm getting the x=0 and y=0.
can u help me..!
in the ui file i have put the graphicsView
/*graphicstest2.h*/
#ifndef GRAPHICSTEST2_H
#define GRAPHICSTEST2_H
#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsItem>
namespace Ui {
class GraphicsTest2;
}
class MyQGraphicsScene;
class GraphicsTest2 : public QMainWindow {
Q_OBJECT
public:
GraphicsTest2(QWidget *parent = 0);
~GraphicsTest2();
void zoomTheItem(QGraphicsSceneMouseEvent *event);
void makeItemNormal(QGraphicsSceneMouseEvent *event);
protected:
void changeEvent(QEvent *e);
private:
Ui::GraphicsTest2 *ui;
MyQGraphicsScene *myScene;
QGraphicsPixmapItem *item1;
QGraphicsItem *currentItem;
bool isItemNotScaled;
};
class MyQGraphicsScene :public QGraphicsScene {
Q_OBJECT
public:
MyQGraphicsScene(GraphicsTest2 *parent);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
GraphicsTest2 *myParent;
};
#endif // GRAPHICSTEST2_H
/*graphicstest2.cpp*/
#include "graphicstest2.h"
#include "ui_graphicstest2.h"
GraphicsTest2::GraphicsTest2(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::GraphicsTest2)
{
isItemNotScaled = true;
myScene = new MyQGraphicsScene(this);
myScene->setSceneRect(0,80,800,460);
item1 = new QGraphicsPixmapItem;
item1->setPixmap(QPixmap("./myimages/addressbook.png"));
myScene->addItem(item1);
item1->setPos(50,130);
ui->setupUi(this);
ui->graphicsView->setScene(myScene);
}
GraphicsTest2::~GraphicsTest2()
{
delete ui;
}
void GraphicsTest2::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void GraphicsTest2::zoomTheItem(QGraphicsSceneMouseEven t *event){
printf("\n zoomIn x:%d,y=%d",event->pos().x(),event->pos().y());fflush(stdout);
currentItem = ui->graphicsView->itemAt(event->pos().x(),event->pos().y());
if(!currentItem){
return;
}
if(isItemNotScaled){
currentItem->setScale(1.25);
currentItem->moveBy(-10,-10);
}
isItemNotScaled = false;
}
void GraphicsTest2::makeItemNormal(QGraphicsSceneMouseE vent *event){
if(!isItemNotScaled){
currentItem->setScale(1);
currentItem->moveBy(10,10);
}
isItemNotScaled = true;
printf("\n zoomOut");fflush(stdout);
}
void MyQGraphicsScene::mousePressEvent(QGraphicsSceneMo useEvent *event){
myParent->zoomTheItem(event);
}
void MyQGraphicsScene::mouseReleaseEvent(QGraphicsScene MouseEvent *event){
myParent->makeItemNormal(event);
}
MyQGraphicsScene::MyQGraphicsScene(GraphicsTest2 *parent){
myParent = parent;
}
/*main.cpp*/
#include <QtGui/QApplication>
#include "graphicstest2.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GraphicsTest2 w;
w.show();
return a.exec();
}
note: Qt 4.6.2
Qt Creator 1.3.1
please help