Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SDL2 works differnetly with widget from code or from ui file
Forum Updated to NodeBB v4.3 + New Features

SDL2 works differnetly with widget from code or from ui file

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 370 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kepeter
    wrote on 14 May 2023, 04:19 last edited by
    #1

    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...

    119227e5-da47-4d43-8d66-7a9fcdc36a76-image.png 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...

    K J 2 Replies Last reply 14 May 2023, 05:33
    0
    • K kepeter
      14 May 2023, 04:19

      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...

      119227e5-da47-4d43-8d66-7a9fcdc36a76-image.png 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...

      K Offline
      K Offline
      Kent-Dorfman
      wrote on 14 May 2023, 05:33 last edited by
      #2

      @kepeter

      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.

      K 1 Reply Last reply 14 May 2023, 15:03
      1
      • K Kent-Dorfman
        14 May 2023, 05:33

        @kepeter

        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.

        K Offline
        K Offline
        kepeter
        wrote on 14 May 2023, 15:03 last edited by
        #3

        @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...

        1 Reply Last reply
        0
        • K kepeter
          14 May 2023, 04:19

          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...

          119227e5-da47-4d43-8d66-7a9fcdc36a76-image.png 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...

          J Offline
          J Offline
          JonB
          wrote on 14 May 2023, 15:15 last edited by
          #4

          @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 into ui_....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.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 14 May 2023, 18:24 last edited by
            #5

            Hi,

            Do you have any SDL error checking done in your code ?
            There might be useful information there.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            3/5

            14 May 2023, 15:03

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved