Results 1 to 4 of 4

Thread: How do I add a QGraphicsScene to a QGridLayout?

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I add a QGraphicsScene to a QGridLayout?

    I have this:
    Qt Code:
    1. class MainWidget(QWidget):
    2. def __init__(self):
    3. self.tree = TreeArea(self)
    4. self.display = DisplayArea(self)
    5.  
    6. gridLayout = QGridLayout()
    7. gridLayout.addWidget(self.tree, 0, 0)
    8. gridLayout.addWidget(self.display, 0, 1)
    To copy to clipboard, switch view to plain text mode 

    where TreeArea is:
    Qt Code:
    1. class TreeArea(QTreeWidget):
    2. def __init__(self, parent):
    3. QTreeWidget.__init__(self, parent)
    To copy to clipboard, switch view to plain text mode 
    and DisplayArea is:
    Qt Code:
    1. class DisplayArea(QGraphicsScene):
    2. def __init__(self, parent):
    3. QGraphicsScene.__init__(self, parent)
    To copy to clipboard, switch view to plain text mode 
    Qt doesn't like it when I do gridLayout.addWidget(self.display, 0, 1) since self.display does not inherit QWidget. So how do I add a QGraphicsScene to a layout?

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QGraphicsScene to a QGridLayout?

    you can add only widgets to a layout. Widgets are those you see on the screen. A QGraphicScene is a model class; in other words stores information/data about a scene. You should create a QGraphicsView and add that to the layout.
    We can't solve problems by using the same kind of thinking we used when we created them

  3. The following user says thank you to sunil.thaha for this useful post:

    di_zou (11th December 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QGraphicsScene to a QGridLayout?

    QGraphicScene is for rendering designing area for QGraphicsView() . so instaed of adding QGraphicsScene u first design a QGraphicsView() with the QGraphicsScene and add that graphicsView to your widget mainwindow
    "Behind every great fortune lies a crime" - Balzac

  5. The following 2 users say thank you to wagmare for this useful post:

    di_zou (11th December 2009), thanyaj (26th November 2010)

  6. #4
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I add a QGraphicsScene to a QGridLayout?

    Thank you, that has worked.

Similar Threads

  1. how to connect events with signals in QGraphicsScene?
    By nataly in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2009, 15:20
  2. Replies: 1
    Last Post: 30th October 2009, 08:52
  3. Replies: 0
    Last Post: 5th March 2009, 06:54
  4. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  5. Qt 3.3 QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 17:40

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.