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:
Code:
#include "widget.h"
#include "ui_widget.h"
#include "samolot.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->graphicsView->setBackgroundBrush(Qt::NoBrush);
scena_sam->setBackgroundBrush(Qt::NoBrush);
scena_sam->setSceneRect(0,0,200,200);
scena_tla->setBackgroundBrush(Qt::green);
scena_tla->setSceneRect(0,0,200,200);
ui->graphicsView->setScene(scena_tla);
ui->graphicsView->setScene(scena_sam);
samolot *sam = new samolot();
scena_sam->addItem(sam);
scena_sam->setFocusItem(sam, Qt::TabFocusReason);
}
Widget::~Widget()
{
delete ui;
}
unfortunately everything I try I faill. The problem is that second scene is alwals white even when I set
Code:
scena_sam->setBackgroundBrush(Qt::NoBrush);
or
Code:
scena_sam->setBackgroundBrush(Qt::transparent);
Maybe my whole concept is wrong, so I would be grateful for other ideas how to achieve this funcionality.
Thanks for any ideas
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
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...
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.
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:)