Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw 2D graphics onto a QOpenGLWidget subclass using QPainter #7

Closed
ytyisme opened this issue Jul 30, 2017 · 7 comments
Closed

Draw 2D graphics onto a QOpenGLWidget subclass using QPainter #7

ytyisme opened this issue Jul 30, 2017 · 7 comments
Assignees

Comments

@ytyisme
Copy link

ytyisme commented Jul 30, 2017

This URL (http://doc.qt.io/qt-5/qopenglwidget.html)show Draw 2D graphics onto a QOpenGLWidget subclass using QPainter.I don't konw why you reimplement the paintEvent() and call makeCurrent() and doneCurrent().

Install Qt5.9.1 with examples, you will find one example qopenglwidget in Qt5.9.1\Examples\Qt-5.9.1\opengl. qopenglwidget is a example show how to Draw 2D graphics onto a QOpenGLWidget subclass using QPainter.I tried to modify your code to make it look like that example. I remove paintEvent(),and put QPainter in paintGL(), but it not works.

You can try it.

@Pseudomanifold
Copy link
Owner

I am not sure what you mean in this issue. Do you want me to remove the paintEvent that I implemented in the widget? In my implementation, I need paintEvent in order to paint the selection rectangle with QPainter. Since the OSG widget displays a mixture of both 3D graphics (OpenSceneGraph) and 2D graphics (QPainter), I thought that this was the best solution. The Qt documentation states that this makes sense, as far as I understand.

@Pseudomanifold Pseudomanifold self-assigned this Jul 30, 2017
@ytyisme
Copy link
Author

ytyisme commented Jul 30, 2017

Now, in the windows platform,can’t display the things QPainter draw when use your code. My English is poor. Most of them are from google translation

@Pseudomanifold
Copy link
Owner

I am sorry, I do not have much experience with programming for Microsoft Windows. I will try to look into this. Can you send me some screenshots maybe?

@ytyisme
Copy link
Author

ytyisme commented Aug 3, 2017

Now show the correct under Windows
I modified as follows

class OSGWidget : public QOpenGLWidget,protected QOpenGLFunctions

void OSGWidget::paintGL()
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(GL_ALL_ATTRIB_BITS);
viewer_->frame();
glPopAttrib();
glPopClientAttrib();
}

Under Windows, you need to add the link library opengl32.lib

@ytyisme ytyisme closed this as completed Aug 3, 2017
@Pseudomanifold
Copy link
Owner

Thank you for these modifications! Is the protected QOpenGLFunctions required?

@ytyisme
Copy link
Author

ytyisme commented Aug 4, 2017

If you do not inherit QOpenGLFunctions then the OpenGL function will not be declared. You may need to include the gl.h header file

@Pseudomanifold
Copy link
Owner

Thank you for the reply! I will refer to this discussion in the README file because, as I said, I do not have sufficient experience with programming for Microsoft Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants