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. OpenGL without using QGLWidget
Qt 6.11 is out! See what's new in the release blog

OpenGL without using QGLWidget

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 6.7k Views 1 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
    Keiko
    wrote on last edited by
    #1

    Hi,

    I would like to use a regular QWidget for my OpenGL drawings, but encounter some problems.

    I installed an eventFilter() to capture the paintEvent for the Widget and am doing all my OpenGL drawing code (including swapping buffers) in there.

    When I return "true" to stop the event being processed any further, the Widget stays gray.. I can't see my OpenGL stuff at all... when I return "false" it start's to flicker between my own Drawings and the Gray default background.

    I also tried to set Attributes like WA_PaintOnScreen and WA_NoSystemBackground, but all they change is that the Widget is no longer gray but black (my OpenGL Clear Color is yellow for test-purposes).

    I am pretty sure I am missing something important like an "erasing the background"-event or something, but can't find anything :(

    Any help would be realy appreciated!

    Cheers,
    Keiko

    PS: I don't want to use the QGLWidget because we already have our whole Engine including initialisation of OpenGL etc.. all I want to do is to use a QWidget's HWND/HDC (on Windows) as Rendertarget..

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrien Leravat
      wrote on last edited by
      #2

      You can use a QGLWidget and call your own full OpenGL initialization/paint stuff from within it (initializeGL, paintGL, etc.). You'd just need to give QGLWidget a pointer to your engine and call your own methods from QGLWidget ones. I did something similar myself previously and didn't encountered any issues.

      Using a regular QWidget to render OpenGL directly on it is surely a harder thing to achieve. Maybe having a look at QGLWidget source would help a bit, if you haven't done so.

      Good luck anyway.

      Adeneo Embedded - www.adeneo-embedded.com

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Keiko
        wrote on last edited by
        #3

        Hi,

        thanks for your reply but we realy don't want to use the QGLWidget.. fancy politics here.. :)

        I already looked at the source of QGLWidget and found out it's setting the WindowFlag Qt::MSWindowsOwnDC on creating and is setting the following Attributes:

        setAttribute(Qt::WA_PaintOnScreen);
        setAttribute(Qt::WA_NoSystemBackground);
        setAutoFillBackground(true);
        

        I did the same for our Widget, but.. no luck :(

        BUT, I noticed our Widget is not just black, actually it's flickering between Black and Yellow (Yellow is our OpenGL Clear Color) - but only when I move the widget to the top of the Screen.. very strange..

        And unfortunately I don't see any big difference between our code and the one of QGLWidget.. But there must be a tiny difference hidden somewhere :(

        Cheers,
        Daniela

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          You might want to check "QWindow":http://qt-project.org/doc/qt-5.0/qtgui/qwindow.html if you are using Qt5 - it offers an OpenGL context without the overhead of QtWidgets.

          Just use:

          @void QWindow::setSurfaceType(QSurface::OpenGLSurface);@

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Adrien Leravat
            wrote on last edited by
            #5

            Did you tried to set the "WA_OpaqueBackground" attribute, andare you sure the original QWidget::paintEvent is inhibited ? (just to be sure :) )

            Adeneo Embedded - www.adeneo-embedded.com

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Keiko
              wrote on last edited by
              #6

              Hi,

              I got it to work - but not sure if it's correct.

              I called my own OpenGL-Draw code in the QEvent::Paint and returned true. Then I called widget.repaint() in a loop so the Paint-Event get's called again, this caused the flickering.

              Now I directly call my OpenGL-Draw method instead of the widget.repaint() - this solved the issues :)

              But, since the repaint-event will be called from time to time from the System I am a bit unsure if I will get a black flashing screen each time.. have to try this out.

              Cheers,
              Keiko

              1 Reply Last reply
              0
              • U Offline
                U Offline
                uwydoc
                wrote on last edited by
                #7

                thanks! it solved the flicker problem i encountered last night.
                actually i had turned off Qt' paint engine, but it made no difference when in fullscreen mode, so i turned it off some time later. however, in windowed mode, it makes a huge difference.

                [quote author="Adrien Leravat" date="1359051022"]are you sure the original QWidget::paintEvent is inhibited ? (just to be sure :) )[/quote]

                1 Reply Last reply
                0

                • Login

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