[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: More: simple graphics on X
>
> I looked both at Qt and GTK+ examples and couldn't find
> how to make a simple window to plot into
>
> I wrote:
> >
> > hi
> >
> > can anyone point me to sources on the web which explin how to make
> > simple X bitmap manipulations ?
> >
> > i need to creat a bitmap on X, and set/clear pixels on real time
> > form a program in c/c++
> >
> > thanks
> > erez.
here is a small Qt example on simple bitmap manipulating
the theory is simple.
you create a qpixmap object.
you paint on it wit a qpainter.
you transfer it to the widget/ write it in the widgets paint
event
--- jail.cpp ----
#include <qapplication.h>
// the following two classes are what is interesting for you
#include <qpixmap.h>
#include <qpainter.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QWidget w;
w.resize( 300, 300 );
// create a pixmap object -- note that you could load a pixmap with
//the constructur that gets a file name as a param..
QPixmap pm(w.width(),w.height());
// create a painter object to work on the pixmap
QPainter p(&pm);
// do the pixel manipulation you want this is just an example
QColorGroup g=w.colorGroup();
p.fillRect(pm.rect(),g.base());
p.setBrush(g.foreground());
for (int i=0;i<=pm.width();i++)
for (int j=0;j<=pm.height();j++)
if (i%8==0||j%8==0)
p.drawPoint(i,j);
// end the painting on the pixmap
p.end();
// transfer the stuff to the widget -- there are other methods, this is
// just one example..
w.setBackgroundPixmap(pm);
// show the widget
a.setMainWidget( &w );
w.show();
return a.exec();
}