Results 1 to 5 of 5

Thread: problem with QGraphicsScene\QGraphicsView

  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with QGraphicsScene\QGraphicsView

    Hi,
    I'm making a simple game the point is I want to put one scene on other scene. Both have the same size. First one will be a background with static and movable items, on second one will be an object which is movable. I order to do such thing I want to set second scene (with an object ) as transparent:

    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include "samolot.h"
    4.  
    5. Widget::Widget(QWidget *parent) : QWidget(parent),
    6. ui(new Ui::Widget)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->graphicsView->setBackgroundBrush(Qt::NoBrush);
    11. scena_tla = new QGraphicsScene(this);
    12. scena_sam = new QGraphicsScene(this);
    13. scena_sam->setBackgroundBrush(Qt::NoBrush);
    14. scena_sam->setSceneRect(0,0,200,200);
    15. scena_tla->setBackgroundBrush(Qt::green);
    16. scena_tla->setSceneRect(0,0,200,200);
    17. ui->graphicsView->setScene(scena_tla);
    18. ui->graphicsView->setScene(scena_sam);
    19. samolot *sam = new samolot();
    20. scena_sam->addItem(sam);
    21. scena_sam->setFocusItem(sam, Qt::TabFocusReason);
    22.  
    23. }
    24.  
    25. Widget::~Widget()
    26. {
    27. delete ui;
    28. }
    To copy to clipboard, switch view to plain text mode 

    unfortunately everything I try I faill. The problem is that second scene is alwals white even when I set

    Qt Code:
    1. scena_sam->setBackgroundBrush(Qt::NoBrush);
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. scena_sam->setBackgroundBrush(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 

    Maybe my whole concept is wrong, so I would be grateful for other ideas how to achieve this funcionality.
    Thanks for any ideas

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QGraphicsScene\QGraphicsView

    Maybe you can do the same with just one scene. You can set individual graphic items to be moveable or static by setting the correct flags to each item. For example: QGraphicsItem::ItemIsMovable and QGraphicsItem::ItemIsSelectable

  3. #3
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with QGraphicsScene\QGraphicsView

    Yes, I'm thinking about this concept too, but I'm trying solution with two scenes at first. Solution with two scenes would be more effective for me and easiest in further development - layer management and others, I guess...
    the whole concept of my game is something like river raid game on C64. On ny first scene background: land, river, tanks, and other movable stuff, second one of course with firing plane. There must be some way to do this...

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QGraphicsScene\QGraphicsView

    But... As far as I know QGraphicsView can only handle one scene at a time:
    void QGraphicsView::setScene ( QGraphicsScene * scene ) and not a collection of scenes

    Also, a layer can be described as a group of graphic items in a scene thus you can implement it with QGraphicsItemGroup.

    You can have a first group in the lowest Z containing land and rivers. Then another group with tanks in Z+1, then your plane in Z+2... And so with all the content.

    Carlos.

  5. The following user says thank you to qlands for this useful post:

    Wojtek_SZ (11th August 2011)

  6. #5
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with QGraphicsScene\QGraphicsView

    After some thought... you have right there isn't such possibility to put more than one scene in to one graphicsView. I decided to change my plans. I gonna use only one scene with your group concept -such layer management seems to be similar to photoshop.
    Thanks for help

Similar Threads

  1. QGraphicsView and QGraphicsScene
    By Molier in forum Qt Programming
    Replies: 11
    Last Post: 28th November 2010, 01:23
  2. mouseMoveEvent problem in QGraphicsView/QGraphicsScene
    By Lendrick in forum Qt Programming
    Replies: 3
    Last Post: 23rd September 2010, 05:26
  3. weird problem in QGraphicsView / QGraphicsScene
    By Mrdata in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2009, 19:26
  4. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 10:10
  5. QGraphicsScene and QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 1st August 2007, 06:59

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.