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. Access to Widget created in Designer
QtWS25 Last Chance

Access to Widget created in Designer

Scheduled Pinned Locked Moved General and Desktop
opengldesignerqt creatorqt5qt5.5qt5.4
5 Posts 2 Posters 3.8k Views
  • 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 Offline
    A Offline
    aidoru
    wrote on last edited by
    #1

    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
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        aidoru
        wrote on last edited by
        #3

        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
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          @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
          2
          • A Offline
            A Offline
            aidoru
            wrote on last edited by
            #5

            Thank you very much Chris

            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