Results 1 to 4 of 4

Thread: Using QGraphicsView with model/view programming

  1. #1
    Join Date
    Jan 2006
    Location
    Bohinjska Bistrica, Slovenia
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Question Using QGraphicsView with model/view programming

    Hi,

    I'm new here and also quite new to Qt4 programming. So far I didn't have any problems with Qt, it is very nice and easy to work with. But now I have stumbled upon a problem, that I'm not sure how to solve best and I hope someone will be able to help me.

    I've started working on a KDE4/Qt4 client called Parsek for playing Thousand Parsec games (similar to Stars! or Galactic Civilizations). In the game you connect to server and you can fetch a list of objects (like stars, planets, spaceships/fleets) in the universe. These objects can be stored in Qt's model/view programming classes.

    Now I would like to use this model with objects and display the objects in 2D using QGraphicsView and related classes in addition to treeview of the universe. What I would like to know is if this is the right way to go here. I did quite some reading about model/view programming and QGraphicsView and as far as I could understand QGraphicsView wasn't designed to be simply plugged in as view for the models.

    So it would be great if someone could tell me if I'm thinking in the right direction and if there are any tips or tricks for making this work together. Are there any tutorials that would be usefull in my case. Thanks in advance for all your help.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QGraphicsView with model/view programming

    I believe this is you who posted on Johan's blog some time ago, so welcome to QtCentre

    You're right, graphics view can't be connected to Interview right away, but you can surely do that and it's a good way to go. I don't think there are any tutorials describing the actual process, but it shouldn't be too hard to implement a connection between the two. Basically you have two choices:
    1. Keep the graphicsview data within the model
    2. Keep references to the model in the scene/items

    Depending which one you choose I believe you'll face different issues.

  3. The following user says thank you to wysota for this useful post:

    JLP (29th January 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Bohinjska Bistrica, Slovenia
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Question Re: Using QGraphicsView with model/view programming

    Yes, that was me posting on blog. After that I didn't have much time to work on Parsek so I didn't look much into it after that. Now I have about two weeks of free time and I plan to use this time learning and working on this.

    So if I understand in your articles about OpenGL (great stuff, thanks a lot for it) you use the first way of doing things, with data kept in custom user roles in model?

    I guess I'm still too much of a beginner to see for real what advantages and dis-advantages any of these two choices would bring Would it be possible if you could point them out? Is there any one way that is easier to do/understand for a newbie like me?

    Thanks again for your help.
    JLP's Blog | Thousand Parsec
    Live long and prosper!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QGraphicsView with model/view programming

    Quote Originally Posted by JLP View Post
    you use the first way of doing things, with data kept in custom user roles in model?
    No, I'm using a completely different approach, don't compare those. I only have a single "database", whereas you have two which have to blend together.

    I guess I'm still too much of a beginner to see for real what advantages and dis-advantages any of these two choices would bring. Would it be possible if you could point them out?
    I can't without experimenting.

    Is there any one way that is easier to do/understand for a newbie like me?
    I think noone has tried such a thing before so it's all white spots on the map.

    It also depends if the scene representation is to be a separate model. If so, I'd probably embed the scene into the model and fetch data directly from the scene and the items themselves (this would give you a simmilar interface to QStandardItemModel). But if it is to be part of a greater model, I'd probably subclass the scene (or something else) and provide a translation between the model indexes and graphics items (that would be the second approach).

Similar Threads

  1. QGraphicsView and game programming
    By ball in forum Newbie
    Replies: 5
    Last Post: 9th January 2007, 21:14
  2. about model/view programming
    By Pang in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2006, 08:42
  3. MODEL/VIEW programming and TABLES
    By newbie in forum Qt Programming
    Replies: 5
    Last Post: 27th August 2006, 21:26
  4. MODEL/VIEW programming
    By mira in forum Newbie
    Replies: 3
    Last Post: 21st April 2006, 11:19
  5. Replies: 2
    Last Post: 16th February 2006, 19:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.