hi all
I am new to Qt and this is my first post here...
I have 2 question to ask :
1.what does boundingrect method in Qgraphicsitem exactly do?
Qt 4 doc says "QGraphicsView uses this to determine whether the item requires redrawing" so we need it to redraw the item.
is there any way not using boundingbox and redraw items?( just implement it like "return QRectF()" )?
2.below is my test code ...why WheelEvent doesnt work???

Qt Code:
  1. test_item.h
  2. #ifndef TEST_ITEM_H
  3. #define TEST_ITEM_H
  4. #include <QGraphicsItem>
  5. class TestItem:public QGraphicsItem
  6. {
  7. public:
  8. TestItem();
  9. private:
  10. protected:
  11. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  12. QRectF boundingRect() const;
  13. };
  14. #endif // TEST_ITEM_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. test_view.h
  2. #ifndef TEST_VIEW_H
  3. #define TEST_VIEW_H
  4. #include <QGraphicsView>
  5. #include <QGraphicsScene>
  6. #include <QWheelEvent>
  7. #include"test_item.h"
  8. class TestView:public QGraphicsView
  9. {
  10. public:
  11. TestView(QWidget* parent=0);
  12. private:
  13. TestItem* item;
  14. protected:
  15. void wheelEvent(QWheelEvent *event);
  16. };
  17. #endif // TEST_VIEW_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. test_item.cpp
  2. #include "test_item.h"
  3. #include <QPainter>
  4. TestItem::TestItem():QGraphicsItem(){}
  5. void TestItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  6. {
  7. painter->drawEllipse(200,200,100,100);
  8. }
  9. QRectF TestItem::boundingRect() const
  10. {
  11. return QRectF(0,0,300,300);
  12. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. test_view.cpp
  2. #include"test_view.h"
  3. #include<QGraphicsEllipseItem>
  4. #include <QMessageBox>
  5. TestView::TestView(QWidget *parent):QGraphicsView(parent)
  6. {
  7. scene=new QGraphicsScene(this),
  8. scene->setSceneRect(0,0,640,480);
  9. this->setScene(scene);
  10.  
  11. item=new TestItem();
  12. scene->addItem(item);
  13. }
  14. void TestView::wheelEvent(QWheelEvent *event)
  15. {
  16. int m_scale=1.8;
  17. if (event->delta() >0)
  18. scale(m_scale,m_scale);
  19. else
  20. scale(1.0/m_scale,1.0/m_scale);
  21. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. main_test.cpp
  2. #include <QApplication>
  3. #include "test_view.h"
  4. int main(int argc,char ** argv)
  5. {
  6. QApplication app(argc,argv);
  7. TestView *v=new TestView();
  8. v->show();
  9. app.exec();
  10. return 0;
  11. }
To copy to clipboard, switch view to plain text mode 

thanks in advance