This simple app calculates the width of a QGraphicsView and displays it in a statusbar and updates the value every time the size changes. Check against your own code to see what's wrong.

Qt Code:
  1. #include <QApplication>
  2. #include <QtGui>
  3.  
  4. class MainWindow : public QMainWindow
  5. {
  6. Q_OBJECT
  7. public:
  8. MainWindow(QWidget* parent=0) : QMainWindow(parent) {
  9. view = new QGraphicsView;
  10. view->installEventFilter(this);
  11. setCentralWidget(view);
  12.  
  13. }
  14. bool eventFilter(QObject* obj, QEvent* event) {
  15. if (obj == view && event->type() == QEvent::Resize)
  16. statusBar()->showMessage(QString::number(view->width()));
  17. return QMainWindow::eventFilter(obj, event);
  18. }
  19. private:
  20.  
  21.  
  22. };
  23.  
  24. #include "main.moc"
  25. int main(int argc, char* argv[])
  26. {
  27. QApplication app(argc, argv);
  28. MainWindow mw;
  29. mw.show();
  30. return app.exec();
  31. }
To copy to clipboard, switch view to plain text mode