Results 1 to 2 of 2

Thread: Newbie needs advice - QGraphics

  1. #1
    Join Date
    Jul 2006
    Posts
    25
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Newbie needs advice - QGraphics

    Thanks in advance

    trying to learn programming and starting with Qt. This is my first program.

    Using a pre-built program Qt 4.2.3 that builds a basic spreadsheet as its central widget
    spreadsheet = new Spreadsheet;
    setCentralWidget(spreadsheet);


    I dont want a spreadsheet, text edit, or anything like that.

    What I want is a blank mainwindow so I can draw lines on it. Just lines, big and small.

    How do I set my central widget and what do I use QGraphicsScene or QGraphicsView? Whats the difference?

    Looking to make my mainwindow an area I can draw lines on but dont know if I use QGraphicsScene or QGraphicsView.

    Also, what would be the code to use?
    QGraphicsView.= new QGraphicsView;
    setCentralWidget(QGraphicsView.);


    Thanks in advance and any help is appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Newbie needs advice - QGraphics

    Close enough:
    Qt Code:
    1. QGraphicsView *view = new QGraphicsView(this);
    2. QGraphicsScene *scene = new QGraphicsScene(view);
    3. scene->setSceneRect( 0, 0, 1000, 1000 ); //you can adjust this as you need
    4. view->setScene(scene);
    5. setCentralWidget(view);
    To copy to clipboard, switch view to plain text mode 

    Next you can start adding items to your scene.
    It would be better to make at least the scene a member of the class, because maybe you want to add items to it as a response to user input, etc( in other functions).

    Also, if you want to provide custom background/foreground for the view ( a grid or a ruler, for example ), then you need to subclass QGraphicsView and reimplement drawBackground/drawForeground.

    Regards

Similar Threads

  1. Newbie needs advice - QGraphicsLineItem
    By Seth in forum Newbie
    Replies: 4
    Last Post: 30th May 2007, 09:23
  2. Newbie needs advice
    By Seth in forum Newbie
    Replies: 3
    Last Post: 12th April 2007, 23:50
  3. Newbie needs advice on moving to designer
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 12th April 2007, 00:32

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.