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.
#include <QApplication>
#include <QtGui>
{
Q_OBJECT
public:
view->installEventFilter(this);
setCentralWidget(view);
}
if (obj
== view
&& event
->type
() == QEvent::Resize) statusBar
()->showMessage
(QString::number(view
->width
()));
}
private:
};
#include "main.moc"
int main(int argc, char* argv[])
{
MainWindow mw;
mw.show();
return app.exec();
}
#include <QApplication>
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent=0) : QMainWindow(parent) {
view = new QGraphicsView;
view->installEventFilter(this);
setCentralWidget(view);
}
bool eventFilter(QObject* obj, QEvent* event) {
if (obj == view && event->type() == QEvent::Resize)
statusBar()->showMessage(QString::number(view->width()));
return QMainWindow::eventFilter(obj, event);
}
private:
QGraphicsView* view;
};
#include "main.moc"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks