0

keypress-event で paintGL メソッドを制御したい。リターンを押して追加点を見せるのが狙い。言い換えれば、私は素敵な背景シーンを描いたので、(lineEdit で) return をプッシュしたいのですが、既に表示されている背景の前に赤い点が表示されます。

//MainWindow.cpp

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    glWidget = new GLWidget;
    connect(ui->lineEdit,   SIGNAL(returnPressed()),    glWidget, SLOT (set_draw()));
}

//glwidget.h

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QMessageBox>
#include "mainwindow.h"
#include "cstdio" 

class MainWindow;

class GLWidget : public QGLWidget
{
 Q_OBJECT
 MainWindow *myMainWindow;   

 public:
    GLWidget(QWidget *parent = 0);
    //~GLWidget;

    int draw;

    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);

public slots:
    void set_draw();
 };
#endif // GLWIDGET_H

//glwidget.cpp

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
{
    draw = 0;
}
//-------------
void GLWidget::set_draw()  //this SLOT is activated by pushing return
{
draw = 1;
updateGL(); //updating paintGL...
}
//-------------
void GLWidget::paintGL()
{
    swapBuffers();
    glClear(GL_COLOR_BUFFER_BIT);

/* drawing a lot of stuff*/

    if( draw == 1 )
    {
/*the following messagebox is shown at the screen*/
QMessageBox* Box = new QMessageBox();
Box->setText("Bert");
Box->show();

/*this big red point is NOT shown at the screen*/
        glPointSize(30);
        glBegin(GL_POINTS);
            glColor3f(1.0, 0.0, 0.0);
            glVertex3f(45,45,0);
        glEnd();
    }

}

なぜこれが機能しないのか、誰かが説明できますか? 赤い点が出ない… の値はint drawpaintGL方式の影響か?

4

1 に答える 1