Hi all,
I’m trying to use SDL to draw on QT widgets (instead of QPainter). So
far i’ve only tried with QT3 for linux.
The intention is to draw some stuff to several alpha-blended surfaces,
and then blit them (with transparency) to the screen on demand (ie when
Widget::paintEvent() is called).
I’ve had mixed success, mostly from the fact that I’m not very
experienced with SDL and so on.
I have first tried using the SDL_WINDOWID and winid() hack, which works
to some extent when there is only one of these QT-SDL widgets in a window.
In the case of just one sdl-surface in a window, each time the window
loses focus the display flickers (using mouse-focus, that means just
waving the mouse in and out of the window). I am guessing that its
caused by setting the videomode each time the widget paints.
When I try adding two of these special widgets into a qt window, only
one gets drawn, for some reason the first widget is drawn on the second
widget’s location.
I was under the (naive?) impression that i could set the WINDOWID each
time before setting the video mode, and then i could draw to that window
until i set the videomode again. Obviously not?
Here is a snippet of the code, I’m not sure how much to paste on this
mailing list. I have a source tarball ready to go for anyone who
requests it. (i have a bad feeling this email is already too long).
Note I’m using the sge library, as it has the primitives i want.
I construct two surfaces “buffer” and “circle” in the widget
constructor. That goes fine. The key part of the code is this:
void QSDL::paintEvent( QPaintEvent* event )
{
QString ids;
setenv(“SDL_WINDOWID”, ids.setNum(winId()), 1);
int w = event->rect().width();
int h = event->rect().height();
SDL_Surface *screen;
screen = SDL_SetVideoMode( w, h, 16, SDL_SWSURFACE );
SDL_BlitSurface(buffer,NULL, screen,NULL);
SDL_UpdateRect( screen, 0, 0, w, h );
}
Thanks
Paul