Results 1 to 3 of 3

Thread: making screen follow Qgraphicsitem

  1. #1
    Join Date
    Mar 2019
    Posts
    3

    Default making screen follow Qgraphicsitem

    How is it possible to make screen follow QGraphicsItem?
    I am trying to make a game and I need that screen follows the player, is there any class I can call or something?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: making screen follow Qgraphicsitem

    There are many QGraphicsView methods that control what part of the scene is displayed in the view:

    QGraphicsView::centerOn()
    QGraphicsView::ensureVisible()
    QGraphicsView::fitInView()
    QGraphicsView::setSceneRect(), etc.

    One of these will probably do what you need.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2019
    Posts
    3

    Default Re: making screen follow Qgraphicsitem

    I am trying to work with centerOn, but can't make it work :s..

    My code looks like this and the centerOn is not doing anything.


    Creating scene:
    Qt Code:
    1. self.scene = QtWidgets.QGraphicsScene()
    2. self.scene.setSceneRect(0, 0, 700, 700)
    3. self.view = QtWidgets.QGraphicsView(self.scene, self)
    To copy to clipboard, switch view to plain text mode 

    Creating rect, that player can control:
    Qt Code:
    1. self.item = QtWidgets.QGraphicsRectItem(-300, 500, 50, 50)
    2. self.item.setBrush(QtGui.QBrush(QtGui.QColor(color[0], color[1],color[2]), QtCore.Qt.SolidPattern))
    3. self.scene.addItem(self.item)
    4. self.newplayer = Player(color, self.starting, self.item, self.view)
    To copy to clipboard, switch view to plain text mode 
    And in Players class init function I am trying to call:
    Qt Code:
    1. self.view.centerOn(self.item)
    To copy to clipboard, switch view to plain text mode 
    Last edited by Nor1; 15th March 2019 at 08:33.

Similar Threads

  1. Replies: 1
    Last Post: 3rd October 2012, 21:48
  2. making qmainwindow dynamically resizable to fit to screen
    By Amit_3117 in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2009, 13:59
  3. How can I follow the mouse?
    By T.I.M in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2009, 09:42
  4. Replies: 4
    Last Post: 11th December 2008, 18:35
  5. QGraphicsItem leaves junk on screen
    By Gopala Krishna in forum Qt Programming
    Replies: 18
    Last Post: 12th December 2007, 07:23

Tags for this Thread

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.