Bonjour à tous,
Après avoir lu de très nombreux post et faq, je m'en remet à vous :
Je veux créer une console sous forme d'une zone de dessin SDL intégrée à un widget Qt :
1. Je crée mon widget, récupère l'ID de la fenetre, initialise Qt
2. Je règle les options de dessin de Qt pour pouvoir effectuer un rendu dans mon QWidget
3. Je veux juste remplir mon rectangle de blanc, et là ca ne fonctionne pas
Voici la classe de mon widget :
Et son implémentation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #ifndef SDLCONSOLETHREAD_H #define SDLCONSOLETHREAD_H #include <QWidget> #include <QThread> #include <SDL/SDL.h> #undef main class SDLConsoleThread : public QThread, public QWidget { Q_OBJECT public: SDLConsoleThread(QWidget *parent = 0); ~SDLConsoleThread(); virtual void run(); private slots: virtual void paintEvent ( ); private: char windowid[64]; // To get Window environment to place the SDL window SDL_Surface *screen; // Display area for the SDL window }; #endif
Je ne vois vraiment pas pourquoi mon widget n'est pas peint :/ (en noir en l'occurence ici SDL_FillRect( screen, 0, 0 ) mais ce n'est pas le pb)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 #include "sdlconsolethread.h" SDLConsoleThread::SDLConsoleThread(QWidget *parent) : QWidget(parent) { // Setting QWidget paint settings to autorize direct rendering into the widget setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); // Setting QWidget Size setMinimumSize ( QSize(400,100) ); // Getting window environment sprintf(windowid, "SDL_WINDOWID=0x%lx", winId()); // Setting SDL environment SDL_putenv(windowid); // Initialisation of SDL if( SDL_Init( SDL_INIT_VIDEO ) == -1 ) { printf( "Can't init SDL: %s\n", SDL_GetError( ) ); } atexit(SDL_Quit); screen = SDL_SetVideoMode( width(),height(), 32, SDL_HWSURFACE ); if( screen == NULL ) { printf( "Can't set video mode: %s\n", SDL_GetError( ) ); } } SDLConsoleThread::~SDLConsoleThread() { qDebug( "Console Thread Exited Normally" ); SDL_FreeSurface( screen ); SDL_Quit(); } void SDLConsoleThread::run() { // while( true ) // { // SDL_Event event; // if (SDL_PollEvent (&event) && event.type==SDL_QUIT) // break; // } } void SDLConsoleThread::paintEvent () { SDL_FillRect( screen, 0, 0 ); SDL_Flip( screen ); }
Si qqun voit la solution ca serait vraiment sympa de m'aider.
Merci d'avance
Partager