Move-able, Re-size-able Graphic Box

Qt Graphics View Lesson 1

Example usage of a custom QGraphicsItem in a QGraphicsScene with examples of mouse hover events.

Download the complete project zip file

screen shot of demo app

This is my first foray into the Qt Graphics View Framework. To get my feet wet, my goal was to create a simpe box, in the shape of a UML State/Class box.
When the user hovers the mouse over the box, it should turn red, and the user should be able to drag the box around the scene.

I created the project with QtCreator. I started a new C++ UI project. But I did not use creator to add widgets to the main window,
but rather created instances of the widgets myself. QtCreator started a mainwindow.h and mainwindow.cpp files (when it created the UI project) – from there I added my widgets.

The class StateBox is the widget that represents the box in the scene. Its derived from the QGraphicsItem. MainWindow.cpp creates the scene and inserts a StateBox object.



I used QtCreator to start a UI project – it creates the skeleton of the MainWindow program which is then the framework where I hang the GraphicsView, GraphicsScene, and scene items
sush as the StateBox and Grid.


Leave a Reply

Trackback this post  |  Subscribe to the comments via RSS Feed