Results 1 to 12 of 12

Thread: QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView

    I've just created a vertical layout and put my graphicsView object inside it. How do I get it to display the graphics? I've tried the following code, but it does not work:

    MainWindow w;

    w.setLayout(&graphicsView);

    Thank you

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsView

    You can create your layout with the QWidget as parent (and the widgets added to layout will be re-parented to the MainWindow/Widget), like this:
    Qt Code:
    1. MainWindow w;
    2. QLabel label = new QLabel; //this will have w as a parent after it's added to the v_layout
    3. //add more widgets to layout
    4. //...
    5. QVBoxLayout *v_layout = new QVBoxLayout(&w);
    6. v_layout->addWidget(label);
    7. //...
    8. w.show(); //you need to show just w
    To copy to clipboard, switch view to plain text mode 

    LE: the code above will work if you use a QWidget as the window (sorry)

    if you use the QMainWindow or derived from it, you will need to parent the layout to a "container" QWidget and then add that QWidget as a centralWidget of your QMainWindow object, something like:
    Qt Code:
    1. MainWindow w;
    2. QWidget *container = new QWidget;
    3. QLabel label = new QLabel; //this will have w as a parent after it's added to the v_layout
    4. //add more widgets to layout
    5. //...
    6. QVBoxLayout *v_layout = new QVBoxLayout(container);
    7. v_layout->addWidget(label);
    8. //...
    9. w.setCentralWidget(container);
    10. w.show(); //you need to show just w
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zlatomir; 18th July 2010 at 23:25.

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

    Maluko_Da_Tola (18th July 2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView

    hum... i'm not too sure about using Layouts... Could you indicate me some readings please?

    Thank you

  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsView

    Small tutorial, it has some links to others..., class reference
    But the best resource to understand quickly, is read a book (i'm reading "Foundations of Qt Development" by Johan Thelin, and it's an excellent book)

Similar Threads

  1. QGraphicsView
    By Yayati.Ekbote in forum Newbie
    Replies: 2
    Last Post: 4th March 2010, 15:10
  2. QGraphicsView
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 09:16
  3. QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2007, 08:00
  4. help with QGraphicsView
    By Erlendhg in forum Qt Programming
    Replies: 6
    Last Post: 22nd April 2007, 20:26
  5. Regarding QGraphicsView
    By kiranraj in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2006, 04:59

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