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. Qpushbutton draws OpenGL problem
Forum Updated to NodeBB v4.3 + New Features

Qpushbutton draws OpenGL problem

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.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.
  • D Offline
    D Offline
    doughng
    wrote on last edited by
    #1

    I'm a newbie to programming, learning by myself to use Qt with OpenGL. I made a button (button1) that just draws an OpenGL object(say object 1), then an Undo button that re-draws the scene without object 1. Now I want to improve on it in such a way that when I click button 1, it draws object 1, and if I click button 1 again, it draws another object 2. And also, the undo button also undo the last draw action.
    Please I need help. I'm a beginner

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      You're diving into the deep end here, learning to program with Qt and OpenGL when you're new to programming! However, I suggest you start learning about container classes such as std::vector, std::list, and [[Doc:QList]]: what you likely want to do is create a new object every time the user presses your button, and add it to a list of objects, which then get drawn. When the user clicks "undo" it simply removes the last item from the list and redraws.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doughng
        wrote on last edited by
        #3

        Thanks, but how can I draw from a QlistWidget, can you please give me a template?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          doughng
          wrote on last edited by
          #4

          I have been able to do that. but how can I draw objects that are currently in the container (qlistwidget) ?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            piercer
            wrote on last edited by
            #5

            In my code I use std::vector and create a base object class that has a virtual Render() call. I then subclass this base class for meshes and primitives. You would then in the main part of your application create a vector to hold these items.

            std::vector<MyDrawClass*> m_objects;

            as the application needs to queue objects to be rendered, you would do something like:

            m_objects.push_back(new Rectangle()); // Rectangle is a sub-class of MyDrawClass

            Then when you are ready to draw them you would do something like:
            @
            void RenderScene() {

            std::vector<MyDrawClass*>::iterator it;
            for(it = m_objects.begin() ; it != m_objects.end; ++it) (*it)->Render();

            }
            @

            And given this example where I'm calling new (I actually use a model library that manages creation/destruction of objects as well as instancing.) when you are done though.

            @myApp::~myApp {
            std::vector<MyDrawClass*>::iterator it;
            for(it = m_objects.begin() ; it != m_objects.end; ++it) delete *it;
            m_objects.clear();
            }@

            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