[Qt-interest] Where to put the control logic in QGraphicsView framework?

Johannes Kleimola johannes at kleimola.fi
Tue Dec 29 14:49:27 CET 2009


Hi!

I want to implement a graphics application (game) with a scene made of 
background tiles and lots of custom items that can be mouse selected and 
dragged as well as keyboard controlled (moves, actions related to other 
items etc). So the full blown widget/ownership will be 
QApplication->QMainWindows->QGraphicsView->QGraphicsScene->QGraphicsItem 
with separate classes (and files) for each of them. The question is, how 
should the control events (mouse, keyboard, event triggered animations, 
setups and cleanups etc) be placed among these files. For example, if I 
select an item with the mouse (handled in QGraphicsScene) and after that 
interact the same item with keyboard (still in QGraphicsScene) but I 
want to center the view to that item simultaneously, that must be made 
in QGraphicsView. Handling the mouse and keyboard events in the item 
itself would make the view centering even "further away" if requested by 
the item. I could also select the item from QGraphicsView class via an 
appropriate pointer returned by scene() function and have the centerOn 
immediately at hand. Finally, everything could be controlled from 
QMainWindow as well with appropriate pointers, but is it ineffective to 
call the scene, view and item getters all the time when controlling from 
parent and/or non-directly-parent elements? Is the QGraphicsView 
framework made purposely fully flexible or is there some guidelines in 
where to control what and why?

Thanks for any advise!

  >> Johannes <<

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Qt-interest-old mailing list