SDL2 works differnetly with widget from code or from ui file
-
I succeeded to connect SDL2 to a widget using code, but when using a winId of a widget coming from the ui (designer) it works only partially...
file:///home/peter/Pictures/Screenshots/Screenshot%20from%202023-05-14%2007-13-32.png
It is obvious that that SDL2 did connect to the top widget (otherwise it wasn't painted black), but the red rectangle (that bouncing left-to-right) shows only on the bottom one.
The top comes from the ui (designer) and the bottom from the code...
Extract from the ui file:
<widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QGraphicsView" name="graphicsView"/> </item> </layout> </widget>
The code adds the second widget (in the constructor of the main window):
ui->setupUi(this); view = new QGraphicsView(); ui->gridLayout->addWidget(view);
The code binds the widgets to SDL2:
void MainWindow::SDLInit() { SetWindow1(SDL_CreateWindowFrom((void *)ui->graphicsView->winId())); SetWindow2(SDL_CreateWindowFrom((void *)view->winId())); SetRenderer1(SDL_CreateRenderer(GetWindow1(), -1, SDL_RENDERER_SOFTWARE)); SetRenderer2(SDL_CreateRenderer(GetWindow2(), -1, SDL_RENDERER_SOFTWARE)); }
I really would like to understand the difference here...
-
I succeeded to connect SDL2 to a widget using code, but when using a winId of a widget coming from the ui (designer) it works only partially...
file:///home/peter/Pictures/Screenshots/Screenshot%20from%202023-05-14%2007-13-32.png
It is obvious that that SDL2 did connect to the top widget (otherwise it wasn't painted black), but the red rectangle (that bouncing left-to-right) shows only on the bottom one.
The top comes from the ui (designer) and the bottom from the code...
Extract from the ui file:
<widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QGraphicsView" name="graphicsView"/> </item> </layout> </widget>
The code adds the second widget (in the constructor of the main window):
ui->setupUi(this); view = new QGraphicsView(); ui->gridLayout->addWidget(view);
The code binds the widgets to SDL2:
void MainWindow::SDLInit() { SetWindow1(SDL_CreateWindowFrom((void *)ui->graphicsView->winId())); SetWindow2(SDL_CreateWindowFrom((void *)view->winId())); SetRenderer1(SDL_CreateRenderer(GetWindow1(), -1, SDL_RENDERER_SOFTWARE)); SetRenderer2(SDL_CreateRenderer(GetWindow2(), -1, SDL_RENDERER_SOFTWARE)); }
I really would like to understand the difference here...
Because you are breaking the framework by managing the widget window independently of the Qt framework. All bets are off when you reference a section of screen real-estate via an X11 winID instead of using the Qt primitives.
There are a "few" legitimate reasons to do this, such as assigning a media player visual to a Qt widget window, but don't expect to rely upon the framework behaving well WRT the shared window region.
FWIW, the QWidget::autoFillBackground gives some minor control over you the widget is painted but it isn't a fix.
I would ask the 10,000$ question of why you feel you must use SDL in a Qt window in the first place.
-
Because you are breaking the framework by managing the widget window independently of the Qt framework. All bets are off when you reference a section of screen real-estate via an X11 winID instead of using the Qt primitives.
There are a "few" legitimate reasons to do this, such as assigning a media player visual to a Qt widget window, but don't expect to rely upon the framework behaving well WRT the shared window region.
FWIW, the QWidget::autoFillBackground gives some minor control over you the widget is painted but it isn't a fix.
I would ask the 10,000$ question of why you feel you must use SDL in a Qt window in the first place.
@Kent-Dorfman
That does not explain the difference... Both windows are passed to SDL2, but only one fully works, the other only partially, and nobody screams about... -
I succeeded to connect SDL2 to a widget using code, but when using a winId of a widget coming from the ui (designer) it works only partially...
file:///home/peter/Pictures/Screenshots/Screenshot%20from%202023-05-14%2007-13-32.png
It is obvious that that SDL2 did connect to the top widget (otherwise it wasn't painted black), but the red rectangle (that bouncing left-to-right) shows only on the bottom one.
The top comes from the ui (designer) and the bottom from the code...
Extract from the ui file:
<widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QGraphicsView" name="graphicsView"/> </item> </layout> </widget>
The code adds the second widget (in the constructor of the main window):
ui->setupUi(this); view = new QGraphicsView(); ui->gridLayout->addWidget(view);
The code binds the widgets to SDL2:
void MainWindow::SDLInit() { SetWindow1(SDL_CreateWindowFrom((void *)ui->graphicsView->winId())); SetWindow2(SDL_CreateWindowFrom((void *)view->winId())); SetRenderer1(SDL_CreateRenderer(GetWindow1(), -1, SDL_RENDERER_SOFTWARE)); SetRenderer2(SDL_CreateRenderer(GetWindow2(), -1, SDL_RENDERER_SOFTWARE)); }
I really would like to understand the difference here...
@kepeter said in SDL2 works differnetly with widget from code or from ui file:
I really would like to understand the difference here...
uic
preprocesses the.ui
file intoui_....h
file in the build output directory. That is the complete C++ code, compare that against your own case which works till you find the difference. -
Hi,
Do you have any SDL error checking done in your code ?
There might be useful information there.