tags:

views:

79

answers:

3

For an experiment, I'd like to create a simple graphical application.

My goal isn't complex: I just need to draw single pixels or lines of different colors, and refresh the view regularly. Something like Conway's Game of Life.

I'm used to work with Qt but never for this kind of task.

What widgets/objects should I use to get started ? Is there anything special I should know/do ?

Thank you.

+1  A: 

Use a QTableView where you implement your own subclass of QAbstractItemDelegate to draw the cells. Take a look at the Pixelator example.

teukkam
+1  A: 

For simple pixel and line drawing, you may want to implement a basic QWidget subclass and implement the paintEvent(). In there you would do your drawing

MyWidget.h:

#ifndef MYWIDGET_H
#define MYWIDGET_H

#include <QWidget>

class MyWidget : public QWidget
{
    Q_OBJECT

    public:
        MyWidget(QWidget *parent = 0);
    protected:
        void paintEvent(QPaintEvent *event);
};

#endif

MyWidget.cpp:

#include <QtGui>

#include "MyWidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
}

void MyWidget::MyWidget(QPaintEvent * /* event */)
{
    QPainter painter(this);

    // Then do things like..
    painter.drawLine(...
    painter.drawRect(...
}

You can find a more complete example here: http://doc.qt.nokia.com/4.6/painting-basicdrawing.html

Arnold Spence
+2  A: 

I'd suggest the "graphics view" framework http://doc.trolltech.com/4.6/graphicsview.html

It is extremely powerful, much more than you need it to be.

Simply, for the creatures in the game of life, create graphics items and set the coordinates for them. Nothing more.

Ivan