Results 1 to 5 of 5

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

  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Default how can I have a fixed overlay layer in a View ?

    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:

    Qt Code:
    1. myCharacter = new character();
    2. scene->addItem(myCharacter);
    3. topFrame = new topframe();
    4. topFrame->setGeometry(0,0,100, 30);
    5. scene->addWidget(topFrame);
    6. QGraphicsView view = new QGraphicsView(scene);
    7. // then I try to update top frame every frame
    8. topFrame->setGeometry(view->pos().x(),0,100,30);
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can I have a fixed overlay layer in a View ?

    May be QGraphicsItem::setFlags(QGraphicsItem::ItemIgnoresTransformations) might help you

  3. #3
    Join Date
    Nov 2009
    Posts
    3

    Default Re: how can I have a fixed overlay layer in a View ?

    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?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can I have a fixed overlay layer in a View ?

    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.
    Last edited by aamer4yu; 18th November 2009 at 06:04.

  5. #5
    Join Date
    Nov 2009
    Posts
    3

    Default Re: how can I have a fixed overlay layer in a View ?

    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

Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  2. Model / View - Design Question
    By antarctic in forum Qt Programming
    Replies: 8
    Last Post: 8th June 2009, 07:39
  3. World View Zooming factor
    By Pharell in forum General Programming
    Replies: 0
    Last Post: 6th November 2008, 13:04
  4. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 19:42
  5. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

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
  •  
Qt is a trademark of The Qt Company.