Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Access to Widget created in Designer

    General and Desktop
    opengl designer qt creator qt5 qt5.5 qt5.4
    2
    5
    3433
    Loading More Posts
    • 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.
    • A
      aidoru last edited by

      Hello,
      I created a widget project with a mainwindow, then in the designer I created an OpenGL Widget.
      Now how can I use GL functions? because I cannot acces for example to my widget just created:

      ui->myGLwidget-paintGL() is impossibile to use because I didn`t declare it

      Could someone help me?

      Thank you

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        You should not call paintGL() directly. Call update() and Qt will schedule a repaint and call it for you, as described here.

        1 Reply Last reply Reply Quote 0
        • A
          aidoru last edited by

          Thank you Chris for your answer.
          So, if I create my OpenGL WIdget in Designer, after that I need to override OpenGL function (paint, resize....and so on), but where I have to do that? I have to create a class with the same name of the widget object I created? My problem is that I would like to know what is the relation between my main source -----> my Qwindow (main window) -------------> my opengl widget created in designer.

          Thank you

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by Chris Kawa

            @aidoru said:

            what is the relation between my main source -----> my Qwindow (main window) -------------> my opengl widget created in designer

            By default - none. Adding QSomeWidget in the designer is essentially doing ui->someWidget = new QSomeWidget() somewhere in the setupUi() method, so it has nothing to do with code in whatever class you written yourself.

            This is a case where you would use widget promotion. Create your own QOpenGLWidget derived class in c++ and implement paintGL and the rest as usual. Then, in the designer, add QOpenGLWidget to the layout. Now right click on the added QOpenGLWidget and select "Promote to...". In the dialog fill in the info about your class (class name and header location) and hit "Add" and "Promote". This will make the generated code create an instance of your class instead of the base QOpenGLWidget (thus "promoting it" to be your class). You can access that instance from code via the usual ui->... pointer.

            1 Reply Last reply Reply Quote 2
            • A
              aidoru last edited by

              Thank you very much Chris

              1 Reply Last reply Reply Quote 0
              • First post
                Last post