PDA

View Full Version : problem with QGraphicsScene\QGraphicsView



Wojtek_SZ
11th August 2011, 10:24
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:



#include "widget.h"
#include "ui_widget.h"
#include "samolot.h"

Widget::Widget(QWidget *parent) : QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);

ui->graphicsView->setBackgroundBrush(Qt::NoBrush);
scena_tla = new QGraphicsScene(this);
scena_sam = new QGraphicsScene(this);
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



scena_sam->setBackgroundBrush(Qt::NoBrush);

or


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

qlands
11th August 2011, 10:46
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

Wojtek_SZ
11th August 2011, 12:45
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...

qlands
11th August 2011, 13:35
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.

Wojtek_SZ
11th August 2011, 15:03
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:)