Nice work so far. The graphicsEditorWidget is good to keep for ui interface purposes. You can use it to connect mouse and keyboard events to appropriate slots within both your View and Scene. To sub-class you'll need an entirely new class (I'll call it MyGraphicsView for lack of a better name). Declare it as follows:
{
Q_OBJECT
public:
protected slots: //Use this if you want the zoom features
}
class MyGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
MyGraphicsView(QGraphicsScene*, QWidget* parent = 0);
protected slots: //Use this if you want the zoom features
void wheelEvent(QWheelEvent* event);
}
To copy to clipboard, switch view to plain text mode
The constructor is fairly straightforward:
MyGraphicsView::MyGraphicsView(QGraphicsScene* s, QWidget* parent) : QGraphicsView(s, parent) { }
To copy to clipboard, switch view to plain text mode
I'll let you fill in other class features as you see fit, but I suggest the wheel event function looks something like:
{
if(event->delta() > 0)
scale(1.1111,1.1111);
else
scale(0.9,0.9);
}
void MyGraphicsView::wheelEvent(QWheelEvent *event)
{
if(event->delta() > 0)
scale(1.1111,1.1111);
else
scale(0.9,0.9);
}
To copy to clipboard, switch view to plain text mode
Finally, to actually use the View, change line 11 in your code above to:
MyGraphicsView* graphView = new MyGraphicsView(graphScene);
MyGraphicsView* graphView = new MyGraphicsView(graphScene);
To copy to clipboard, switch view to plain text mode
See if that get's you going on how this all works.
Bookmarks