C++ 如何在mousepressEvent()函数中显示像素坐标,然后如何在每次单击鼠标时在paintGL()函数中使用它们
我正在QT4IDE中的opengl上创建一个gui。我创建了一个带有opengl窗口的小部件,在那里我可以显示[b]曲线[/b]。这里我使用[b]paintGL()[/b]并在其中调用绘图函数进行显示。但我的问题是,这里我使用[b]mousePressEvent(QMouseEvent*event)[/b]获取像素坐标,以便单击opengl窗口,我可以在特定的单击位置生成曲线。但运行程序后,我发现初始绘图功能和生成的曲线。但在单击窗口后无法更新,但在控制台应用程序中执行的所有计算中,只有显示未更新 那么,在这个窗口上单击鼠标后,如何更新opengl窗口呢 以下是我的源代码: GlWidget.cppC++ 如何在mousepressEvent()函数中显示像素坐标,然后如何在每次单击鼠标时在paintGL()函数中使用它们,c++,opengl,qt4,C++,Opengl,Qt4,我正在QT4IDE中的opengl上创建一个gui。我创建了一个带有opengl窗口的小部件,在那里我可以显示[b]曲线[/b]。这里我使用[b]paintGL()[/b]并在其中调用绘图函数进行显示。但我的问题是,这里我使用[b]mousePressEvent(QMouseEvent*event)[/b]获取像素坐标,以便单击opengl窗口,我可以在特定的单击位置生成曲线。但运行程序后,我发现初始绘图功能和生成的曲线。但在单击窗口后无法更新,但在控制台应用程序中执行的所有计算中,只有显示未更
//////Mouse Click Event for finding the pixel values//////
void GLWidget::mousePressEvent(QMouseEvent *event)
{
float window_width,window_height;
float ratio_x,ratio_y,cy;
click_x=event->x();
click_y=event->y();
// qDebug()<<"screen cx1==="<<cx1;
// qDebug()<<"screen cy1==="<<cy1;
window_width = 800;
window_height = 600;
ratio_x=30.0/window_width;
ratio_y=30.0/window_height;
cy=window_height-click_y;
click_x=click_x*ratio_x-10;
click_y=cy*ratio_y-10;
qDebug()<<"original_position_on_screen x==="<<click_x;
qDebug()<<"original_position_on_screen y==="<<click_y;
count=count+1;
qDebug()<<"count==="<<count;
func();
}
void GLWidget::func()
{
Draw_Curve(); //Drawing function
}
void GLWidget::Draw_Curve()
{
//Draw The Curve
}
void GLWidget:: paintGL() // paintGL() function
{
glClear(GL_COLOR_BUFFER_BIT);
Draw_Axes(); //Draw 3d coordinate axes
func(); //in this function we get the pixel coordinates everytime the mouse is clicked in the window
}
查找像素值的鼠标单击事件//////
void GLWidget::MousePresseEvent(QMouseEvent*事件)
{
浮动窗宽、窗高;
浮动比率x,比率y,cy;
单击事件->x();
单击_y=event->y();
//qDebug()有几件事:
- 您应该请求更新,而不是调用函数来呈现鼠标事件处理程序中的任何内容
void GLWidget::mousePressEvent(QMouseEvent *event) { float window_width,window_height; float ratio_x,ratio_y,cy; click_x=event->x(); click_y=event->y(); // qDebug()<<"screen cx1==="<<cx1; // qDebug()<<"screen cy1==="<<cy1; window_width = 800; window_height = 600; ratio_x=30.0/window_width; ratio_y=30.0/window_height; cy=window_height-click_y; click_x=click_x*ratio_x-10; click_y=cy*ratio_y-10; qDebug()<<"original_position_on_screen x==="<<click_x; qDebug()<<"original_position_on_screen y==="<<click_y; count=count+1; qDebug()<<"count==="<<count; update(); // to request image update }
void GLWidget::mousePressEvent(QMouseEvent*event) { 浮动窗宽、窗高; 浮动比率x,比率y,cy; 单击事件->x(); 单击_y=event->y();
//qDebug()谢谢你的回答。但是我的问题没有解决。屏幕上的轴和绘图曲线在每次鼠标点击后都会变短。如果可以,请给出建议。提前谢谢