Unsolved QWidget with QopenGLwidget
-
How can I bind Qwidget in to QopenGLwidget?
-
Hi,
What exactly do you want to do ?
-
@SGaist I have created one line in QopenGlWidget. one point of this line is fixed and at another point there is a widget.
now,When I drag that widget the line should not be seperated from widget(this problem I am facing here).
So,I want to bind that widget with that line point. -
Can you show how you are doing that ?
-
Not completed yet,
#include "openglclass.h" openGlClass::openGlClass(QWidget *parent):QOpenGLWidget(parent) { count=0; W= new QWidget(this); W->setStyleSheet("background-color : rgb(0,170,127);"); W->setFixedSize(50,40); QPoint pl= W->geometry().bottomLeft(); QPoint pr= W->geometry().bottomRight(); qDebug()<<"point : "<<pr << pl; W->show(); } void openGlClass::initializeGL() { qDebug()<<"Initialize"<<count ; //initializeOpenGLFunctions(); glClearColor(0.7,0.7,0.7,1); glEnable(GL_LIGHTING); } void openGlClass::paintGL() { qDebug()<<"paint"<<count; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINES); glColor3f(1,0,0); glVertex2f(0.1f, 0.7f); glVertex2f(-0.9f, 0.1f); glEnd(); } void openGlClass::resizeGL(int w, int h) { qDebug()<<"Resize"<<count; } void openGlClass::mousePressEvent(QMouseEvent *event) { }
O/p:
The Green Box is simple widget and line I have Render in OpenGl,not i want to Bind both so that when i Drag that box the line Should also adjust with that.
-
@hjohn said in QWidget with QopenGLwidget:
QPoint pl= W->geometry().bottomLeft();
QPoint pr= W->geometry().bottomRight();These should be class variables. ( live in .h)
and u do
pl= W->geometry().bottomLeft();
pr= W->geometry().bottomRight();
and also updates them when you move the widget
and then use them in the
void openGlClass::paintGL()
for the line drawings. -
@mrjj But Problem is that, Qwidget coordinate system and openGL coordinate system are different.
In Qwidget,the Origin(0,0) is on top left corner whereas In QOpenglwidget origin(0,0) is centered.
So,when in Widget if we set Geometry as aW->setGeometry(0,0,50,40);
and in line
glBegin(GL_LINE); glVertex2f(0.0f, 0.0f); glVertex2f(0.5f, 0.5f); glEnd();
Both are rendered in Diffetnt place.
the Geometry position of widget is set based on Qpoint.
In openGl is based on Veretex. I have manually scale the values.But how to set it dynamically.Any idea? -
yep they live in completely different world.
You have to make a function that maps between Widget x,y to openGl
or find a better way to archive what u want.Normally one would paint the widget to a texture and show on a plane
inside the openGl or similar ways. I also think u can paint with QPainter.Do you really need the lines to be opengl?
-
@mrjj said in QWidget with QopenGLwidget:
Normally one would paint the widget to a texture and show on a plane
If I paint Widget then there is no chance to add something or modify the values display on widget,and I want some data to be displayed on that widget.
Yes,I need that Line to be OpenGl@mrjj said in QWidget with QopenGLwidget:
You have to make a function that maps between Widget x,y to openGl
Do You have any Idea,the way to map coordinates.
-
How Can I find coordinates of openGLwidget when mouse press.
-
Hi
Sorry. i have no good idea how to convert in any easy way.By mouse Coordinates you mean in Widgets coordinates or as
actual openGl coordinates? -
@mrjj said in QWidget with QopenGLwidget:
By mouse Coordinates you mean in Widgets coordinates or as
actual openGl coordinates?Actual OpenGl coordinates.
-
@hjohn
I do not think openGLwidget directly offer that.
I tried to google for it but just too much deprecated fixed pipeline
openGl so im not sure how you would do it.This would be very easy to do with QPainter but i guess you want
openGl for a reason ? -
@mrjj yeah..
No worry.. If I come up with any solution,I will mention here. Thanks for guiding me..