PDA

View Full Version : how can I have a fixed overlay layer in a View ?



Jaymz
18th November 2009, 03:09
I'm doing a game in which the QGraphicsItem character is moved by the left/right keys and then, the scene is scrolled inside the view. But I also want to put a top frame with game points, timers and so on. The top frame is of type QHBoxLayout. What I have so far is:



QGraphicsScene scene;
myCharacter = new character();
scene->addItem(myCharacter);
topFrame = new topframe();
topFrame->setGeometry(0,0,100, 30);
scene->addWidget(topFrame);
QGraphicsView view = new QGraphicsView(scene);
// then I try to update top frame every frame
topFrame->setGeometry(view->pos().x(),0,100,30);


the good news is this actually works and moves the top frame when left/right keys are pressed, but the character is moving way much faster than the top frame which falls behind and slowly gets outside of the view. Is it possible to do the top frame in some other way to have it fixed as an additional layer of the view or something like that?

aamer4yu
18th November 2009, 05:17
May be QGraphicsItem::setFlags(QGraphicsItem::ItemIgnores Transformations) might help you

Jaymz
18th November 2009, 05:36
I don't get it. my character is the one who's a QGraphicsItem, but I thought I have to do something with the view/scene/QWidget/QHBoxLayout which is related to my top frame. All I want is the top frame to be stuck within the view and not move when the scene is scrolling. Am I missing something here?

aamer4yu
18th November 2009, 05:59
Sorry, I guess I replied in a hurry.
Well, in that case why dont you make the topFrame as a child of view ? I dont think it is compulsory to make it a graphics item.
The top frame would need to have transparent background.

By the way if you dont have any interaction with the topframe, ie. no clicking or key press on it, and simply rendering, better way would be to simply draw in QGraphicsScene::drawForeground or QGraphicsView::drawBackground


If I come across some other solution I will let you know.

Jaymz
18th November 2009, 15:39
I kind of get some of your idea, but I would need an example to understand better. The topFrame has nothing to do with clicks or key pressing, but it needs to display some objects like timers, scores, etc.

For the given code in my first reply, could you please make an example on how would you create the topFrame and incorporate it in the view? thank you