Results 1 to 8 of 8

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 10:33.

Similar Threads

  1. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 16:16
  2. Replies: 1
    Last Post: 16th November 2009, 05:25
  3. QGLWidget with text - zoom in / zoom out
    By h123 in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 09: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, 11:29
  5. any body using qextserialport?
    By yagabey in forum Newbie
    Replies: 4
    Last Post: 25th December 2007, 22: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.