PDA

View Full Version : Newbie needs advice - QGraphics



Seth
26th June 2007, 02:36
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. :)

marcel
26th June 2007, 05:12
Close enough:


QGraphicsView *view = new QGraphicsView(this);
QGraphicsScene *scene = new QGraphicsScene(view);
scene->setSceneRect( 0, 0, 1000, 1000 ); //you can adjust this as you need
view->setScene(scene);
setCentralWidget(view);


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