Results 1 to 8 of 8

Thread: I can't ZOOM THE ICONS can any body help me..!

  1. #1
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Exclamation I can't ZOOM THE ICONS can any body help me..!

    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

    Qt Code:
    1. /*graphicstest2.h*/
    2.  
    3. #ifndef GRAPHICSTEST2_H
    4. #define GRAPHICSTEST2_H
    5.  
    6. #include <QMainWindow>
    7. #include <QGraphicsScene>
    8. #include <QGraphicsPixmapItem>
    9. #include <QGraphicsSceneMouseEvent>
    10. #include <QGraphicsItem>
    11.  
    12. namespace Ui {
    13. class GraphicsTest2;
    14. }
    15.  
    16. class MyQGraphicsScene;
    17.  
    18. class GraphicsTest2 : public QMainWindow {
    19. Q_OBJECT
    20. public:
    21. GraphicsTest2(QWidget *parent = 0);
    22. ~GraphicsTest2();
    23.  
    24. void zoomTheItem(QGraphicsSceneMouseEvent *event);
    25. void makeItemNormal(QGraphicsSceneMouseEvent *event);
    26.  
    27.  
    28. protected:
    29. void changeEvent(QEvent *e);
    30.  
    31.  
    32. private:
    33. Ui::GraphicsTest2 *ui;
    34. MyQGraphicsScene *myScene;
    35.  
    36. QGraphicsItem *currentItem;
    37. bool isItemNotScaled;
    38.  
    39.  
    40.  
    41. };
    42.  
    43. class MyQGraphicsScene :public QGraphicsScene {
    44. Q_OBJECT
    45. public:
    46. MyQGraphicsScene(GraphicsTest2 *parent);
    47. protected:
    48. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    49. void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    50.  
    51. private:
    52. GraphicsTest2 *myParent;
    53.  
    54.  
    55. };
    56.  
    57. #endif // GRAPHICSTEST2_H
    58.  
    59. /*graphicstest2.cpp*/
    60.  
    61. #include "graphicstest2.h"
    62. #include "ui_graphicstest2.h"
    63.  
    64. GraphicsTest2::GraphicsTest2(QWidget *parent) :
    65. QMainWindow(parent),
    66. ui(new Ui::GraphicsTest2)
    67. {
    68. isItemNotScaled = true;
    69.  
    70. myScene = new MyQGraphicsScene(this);
    71. myScene->setSceneRect(0,80,800,460);
    72. item1 = new QGraphicsPixmapItem;
    73. item1->setPixmap(QPixmap("./myimages/addressbook.png"));
    74.  
    75.  
    76. myScene->addItem(item1);
    77. item1->setPos(50,130);
    78.  
    79. ui->setupUi(this);
    80. ui->graphicsView->setScene(myScene);
    81. }
    82.  
    83. GraphicsTest2::~GraphicsTest2()
    84. {
    85. delete ui;
    86. }
    87.  
    88. void GraphicsTest2::changeEvent(QEvent *e)
    89. {
    90. QMainWindow::changeEvent(e);
    91. switch (e->type()) {
    92. case QEvent::LanguageChange:
    93. ui->retranslateUi(this);
    94. break;
    95. default:
    96. break;
    97. }
    98. }
    99.  
    100. void GraphicsTest2::zoomTheItem(QGraphicsSceneMouseEvent *event){
    101. printf("\n zoomIn x:%d,y=%d",event->pos().x(),event->pos().y());fflush(stdout);
    102. currentItem = ui->graphicsView->itemAt(event->pos().x(),event->pos().y());
    103.  
    104. if(!currentItem){
    105. return;
    106. }
    107.  
    108. if(isItemNotScaled){
    109. currentItem->setScale(1.25);
    110. currentItem->moveBy(-10,-10);
    111. }
    112. isItemNotScaled = false;
    113.  
    114.  
    115.  
    116. }
    117.  
    118. void GraphicsTest2::makeItemNormal(QGraphicsSceneMouseEvent *event){
    119. if(!isItemNotScaled){
    120. currentItem->setScale(1);
    121. currentItem->moveBy(10,10);
    122. }
    123. isItemNotScaled = true;
    124. printf("\n zoomOut");fflush(stdout);
    125. }
    126.  
    127. void MyQGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){
    128. myParent->zoomTheItem(event);
    129. }
    130.  
    131. void MyQGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    132.  
    133. myParent->makeItemNormal(event);
    134.  
    135. }
    136.  
    137.  
    138. MyQGraphicsScene::MyQGraphicsScene(GraphicsTest2 *parent){
    139. myParent = parent;
    140.  
    141. }
    142.  
    143.  
    144. /*main.cpp*/
    145.  
    146. #include <QtGui/QApplication>
    147. #include "graphicstest2.h"
    148.  
    149. int main(int argc, char *argv[])
    150. {
    151. QApplication a(argc, argv);
    152. GraphicsTest2 w;
    153. w.show();
    154. return a.exec();
    155. }
    To copy to clipboard, switch view to plain text mode 


    note: Qt 4.6.2
    Qt Creator 1.3.1



    please help
    Last edited by jthacker; 1st June 2010 at 11:33.

  2. #2
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    help please...!
    thankx

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    First please re-consider you design. It seems quite complex for a simple task.
    You need not pass the event to myParent.. you can handle items from within the scene. So use of GraphicsTest2 *myParent; in ur scene class seems irrelevant.

    Then coming how to zoom in / out . You just need to use QGraphicsView::fitInView. For zoom in, you can pass the item itself...for zoom out, manipulate the scene rect you want to show and call fitInview.

  4. #4
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    hey,
    i have modified the this in the simpler one...!
    and one thing to say that i have 6 to 9 app icons on the scene...!
    and i want to zoom one app icon at a time to the factor 1.25 ....!
    here is the code:
    i'm still getting the x=0,y=0;
    i have tried to give manual value in
    in mousePressEvent()
    currentItem=itemAt(55,135);

    i'm not getting the item at given coordinate.
    Qt Code:
    1. /*graphicstest2.h*/
    2.  
    3. #ifndef GRAPHICSTEST2_H
    4. #define GRAPHICSTEST2_H
    5.  
    6. #include <QMainWindow>
    7. #include <QGraphicsScene>
    8. #include <QGraphicsPixmapItem>
    9. #include <QGraphicsSceneMouseEvent>
    10. #include <QGraphicsItem>
    11.  
    12. namespace Ui {
    13. class GraphicsTest2;
    14. }
    15.  
    16. class MyQGraphicsScene;
    17.  
    18. class GraphicsTest2 : public QMainWindow {
    19. Q_OBJECT
    20. public:
    21. GraphicsTest2(QWidget *parent = 0);
    22. ~GraphicsTest2();
    23.  
    24. //void zoomTheItem(QGraphicsSceneMouseEvent *event);
    25. //void makeItemNormal(QGraphicsSceneMouseEvent *event);
    26.  
    27.  
    28. protected:
    29. void changeEvent(QEvent *e);
    30.  
    31.  
    32. private:
    33. Ui::GraphicsTest2 *ui;
    34. MyQGraphicsScene *myScene;
    35.  
    36. };
    37.  
    38. class MyQGraphicsScene :public QGraphicsScene {
    39. Q_OBJECT
    40. public:
    41. MyQGraphicsScene();
    42. protected:
    43. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    44. void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    45.  
    46. private:
    47. //GraphicsTest2 *myParent;
    48. QGraphicsItem *currentItem;
    49. bool isItemNotScaled;
    50.  
    51.  
    52. };
    53.  
    54. #endif // GRAPHICSTEST2_H
    55.  
    56.  
    57. /* graphicstest2.cpp*/
    58. #include "graphicstest2.h"
    59. #include "ui_graphicstest2.h"
    60.  
    61. GraphicsTest2::GraphicsTest2(QWidget *parent) :
    62. QMainWindow(parent),
    63. ui(new Ui::GraphicsTest2)
    64. {
    65.  
    66.  
    67. myScene = new MyQGraphicsScene;
    68. myScene->setSceneRect(0,80,800,460);
    69. item1 = new QGraphicsPixmapItem;
    70. item1->setPixmap(QPixmap("./myimages/addressbook.png"));
    71. item1->setPos(50,130);
    72.  
    73. item2 = new QGraphicsPixmapItem;
    74. item2->setPixmap(QPixmap("./myimages/flash.png"));
    75. item2->setPos(250,130);
    76.  
    77. item3 = new QGraphicsPixmapItem;
    78. item3->setPixmap(QPixmap("./myimages/games.png"));
    79. item3->setPos(400,130);
    80.  
    81. myScene->addItem(item1);
    82. myScene->addItem(item2);
    83. myScene->addItem(item3);
    84.  
    85.  
    86. ui->setupUi(this);
    87. ui->graphicsView->setScene(myScene);
    88. }
    89.  
    90. GraphicsTest2::~GraphicsTest2()
    91. {
    92. delete ui;
    93. }
    94.  
    95. void GraphicsTest2::changeEvent(QEvent *e)
    96. {
    97. QMainWindow::changeEvent(e);
    98. switch (e->type()) {
    99. case QEvent::LanguageChange:
    100. ui->retranslateUi(this);
    101. break;
    102. default:
    103. break;
    104. }
    105. }
    106.  
    107. //void GraphicsTest2::zoomTheItem(QGraphicsSceneMouseEvent *event){}
    108. //void GraphicsTest2::makeItemNormal(QGraphicsSceneMouseEvent *event){}
    109.  
    110. void MyQGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){
    111. //yParent->zoomTheItem(event);
    112.  
    113. printf("\n zoomIn x:%f,y=%f",event->pos().x(),event->pos().y());fflush(stdout);
    114.  
    115. currentItem = itemAt(event->pos().x(),event->pos().y());
    116.  
    117. if(!currentItem){
    118. return;
    119. }
    120.  
    121. if(isItemNotScaled){
    122. currentItem->setScale(1.25);
    123. currentItem->moveBy(-10,-10);
    124. }
    125. isItemNotScaled = false;
    126.  
    127. }
    128.  
    129. void MyQGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    130. printf("\n zoomIn x:%f,y=%f",event->pos().x(),event->pos().y());fflush(stdout);
    131. //myParent->makeItemNormal(event);
    132.  
    133. if(!isItemNotScaled){
    134. currentItem->setScale(1);
    135. currentItem->moveBy(10,10);
    136. }
    137. isItemNotScaled = true;
    138. printf("\n zoomOut");fflush(stdout);
    139.  
    140. }
    141.  
    142.  
    143. MyQGraphicsScene::MyQGraphicsScene(){
    144. // myParent = parent;
    145. isItemNotScaled = true;
    146.  
    147. }
    To copy to clipboard, switch view to plain text mode 



    plz help..!

  5. #5
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    hey aamer4yu where are you..!
    can anybody help in this...!

    thanx

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    Quote Originally Posted by jthacker View Post
    hey aamer4yu where are you..!
    Hey! Why you can't wait more then 25 minutes? There is no need to beg for answers every hour. Better use the time while you are waiting to read the documentation about QGraphicsSceneMouseEvent. You might want have a closer look at QGraphicsSceneMouseEvent::scenePos().

  7. #7
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Exclamation Re: I can't ZOOM THE ICONS can any body help me..!

    hey ..!
    thanx for your nice feedback..! i got the solution for the zooming effect...!
    But i in this i'm facing another problem when i run the following modified code..!

    when i press mouse: mousePressEvent() is called and icon is getting zoomed but
    when i release the mouse : mouseReleaseEvent() is not getting called...! and item remains in zoomed position

    but when i press & release mouse out side the GraphicsView area at that time the both function are called...!
    Qt Code:
    1. /*graphicstest2.cpp*/
    2.  
    3. #ifndef GRAPHICSTEST2_H
    4. #define GRAPHICSTEST2_H
    5.  
    6. #include <QMainWindow>
    7. #include <QGraphicsScene>
    8. #include <QGraphicsPixmapItem>
    9. #include <QGraphicsSceneMouseEvent>
    10. #include <QGraphicsItem>
    11.  
    12. namespace Ui {
    13. class GraphicsTest2;
    14. }
    15.  
    16. class GraphicsTest2 : public QMainWindow {
    17. Q_OBJECT
    18. public:
    19. GraphicsTest2(QWidget *parent = 0);
    20. ~GraphicsTest2();
    21.  
    22.  
    23. protected:
    24. void changeEvent(QEvent *e);
    25. void mousePressEvent(QMouseEvent *event);
    26. void mouseReleaseEvent(QMouseEvent *event);
    27.  
    28. private:
    29. Ui::GraphicsTest2 *ui;
    30. QGraphicsScene *myScene;
    31.  
    32. QGraphicsItem *currentItem;
    33.  
    34. };
    35.  
    36. #endif // GRAPHICSTEST2_H
    37.  
    38. /*graphicstest2.cpp*/
    39.  
    40. #include "graphicstest2.h"
    41. #include "ui_graphicstest2.h"
    42. #include <iostream>
    43. #include <QMouseEvent>
    44. GraphicsTest2::GraphicsTest2(QWidget *parent) :
    45. QMainWindow(parent),
    46. ui(new Ui::GraphicsTest2)
    47. {
    48.  
    49.  
    50. myScene = new QGraphicsScene;
    51. myScene->setSceneRect(0,80,800,460);
    52. item1 = new QGraphicsPixmapItem;
    53. item1->setPixmap(QPixmap("./myimages/addressbook.png"));
    54. item1->setPos(50,130);
    55.  
    56. item2 = new QGraphicsPixmapItem;
    57. item2->setPixmap(QPixmap("./myimages/flash.png"));
    58. item2->setPos(250,130);
    59.  
    60. item3 = new QGraphicsPixmapItem;
    61. item3->setPixmap(QPixmap("./myimages/games.png"));
    62. item3->setPos(400,130);
    63.  
    64. myScene->addItem(item1);
    65. myScene->addItem(item2);
    66. myScene->addItem(item3);
    67.  
    68.  
    69.  
    70. ui->setupUi(this);
    71. ui->graphicsView->setScene(myScene);
    72.  
    73. }
    74.  
    75. GraphicsTest2::~GraphicsTest2()
    76. {
    77. delete ui;
    78. }
    79.  
    80. void GraphicsTest2::changeEvent(QEvent *e)
    81. {
    82. QMainWindow::changeEvent(e);
    83. switch (e->type()) {
    84. case QEvent::LanguageChange:
    85. ui->retranslateUi(this);
    86. break;
    87. default:
    88. break;
    89. }
    90. }
    91.  
    92.  
    93. void GraphicsTest2::mousePressEvent(QMouseEvent *event){
    94.  
    95. std::cout<<qPrintable(QString("\n main press x=%1,y=%2").arg(event->pos().x()).arg(event->pos().y()));fflush(stdout);
    96.  
    97.  
    98. currentItem = ui->graphicsView->itemAt(event->pos().x(),event->pos().y()-80);
    99. if(currentItem)
    100. currentItem->setScale(1.25);
    101.  
    102.  
    103.  
    104. }
    105.  
    106. void GraphicsTest2::mouseReleaseEvent(QMouseEvent *event){
    107.  
    108. std::cout<<qPrintable(QString("\n main release x=%1,y=%2").arg(event->pos().x()).arg(event->pos().y()));fflush(stdout);
    109.  
    110. if(currentItem){
    111. currentItem->setScale(1);
    112. currentItem=0;
    113. }
    114. }
    To copy to clipboard, switch view to plain text mode 

    thank you...!
    Last edited by jthacker; 1st June 2010 at 14:55.

  8. #8
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: I can't ZOOM THE ICONS can any body help me..!

    hey can anybody help in this ...!
    why the mouseReleaseEvent() is not getting called...!


    thank you.
    any comments...?

Similar Threads

  1. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 17:16
  2. Replies: 1
    Last Post: 16th November 2009, 06:25
  3. QGLWidget with text - zoom in / zoom out
    By h123 in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 10:56
  4. Any body who have a ping soure code using qt ?
    By longtrue in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2008, 12:29
  5. any body using qextserialport?
    By yagabey in forum Newbie
    Replies: 4
    Last Post: 25th December 2007, 23:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.