Results 1 to 3 of 3

Thread: When to use QGraphicsScene or QWidget

  1. #1

    Default When to use QGraphicsScene or QWidget

    I'm a little confused as to WHEN you want to use a QWidget and WHEN you want to use a QGraphicsScene, could somebody elaborate on that or point me to some docs that have already covered it? I'm having a difficult time finding such information.

    For instance, take the demo Tetrix, could you use a QGraphicsScene for the "board" area where all tetris blocks are? Or is QGraphicsScene limited to requiring the entire space of the window at all times?

    Any help would be appreciated. Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When to use QGraphicsScene or QWidget

    Quote Originally Posted by fossill View Post
    I'm a little confused as to WHEN you want to use a QWidget and WHEN you want to use a QGraphicsScene
    Actually you always have to use QWidget or one of its subclasses. A special case of a widget is QGraphicsView which is capable of displaying QGraphicsScene and QGraphicsItems that scene contains.

    Quote Originally Posted by fossill View Post
    For instance, take the demo Tetrix, could you use a QGraphicsScene for the "board" area where all tetris blocks are?
    Yes, you could. You can also subclass QWidget and do all of the drawing yourself, but it will be much easier if you use QGraphicsScene and QGraphicsItems.

    Quote Originally Posted by fossill View Post
    Or is QGraphicsScene limited to requiring the entire space of the window at all times?
    No, it's not. QGraphicsView behaves just like other widgets, so you can use QWidget::setGeometry() or layouts to place it wherever you want.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: When to use QGraphicsScene or QWidget

    If I were to make a rule of a thumb, I'd say that you should use QGraphicsView whenever you want to create a large amount of objects that either change their state very often (animate) or require interaction with the user (selecting, moving, zooming). In other situations use QWidget.

Similar Threads

  1. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 09:25
  2. Transparent QWidget on QGLWidget
    By showhand in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 02:00
  3. QWidget item in QGraphicsScene
    By IUnknown in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 01:05
  4. Replies: 1
    Last Post: 2nd May 2006, 22:11
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 23:59

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.