我在QMainWindow里面用QSplitter划分出一个继承于QGLWidget的SmallGraph,然后在SmallGraph窗口里面画上Gradient样式的背景,还画些线
但是当我用其它窗口遮挡住这个子窗口后或者手动拉伸,压缩这个子窗口后,(即更新子窗口)子窗口里面画的线还在,但是背景消失了,这是为何?画背景和画线都是写在paintEvent里面的啊?
求助
SmallGraph::SmallGraph(QWidget *, const QGLWidget *, Qt::WindowFlags )
: QGLWidget()
{
//setGeometry(4, 30, 800, 600);
createGradient();
}
SmallGraph::~SmallGraph()
{
}
void SmallGraph::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
{
emit sig_maomaoPressed();
}
}
void SmallGraph::DrawLink()
{
for (int i=0;i<iMainWindow::LinkList.size();i++)
{
glBegin( GL_LINES );
glColor3f( 1.0, 0.0, 0.0 );
glVertex2f(((iMainWindow::LinkList.first)->iNodeX-Xmax/2)/12, ((iMainWindow::LinkList.first)->iNodeY-Ymax/2)/12);
glVertex2f(((iMainWindow::LinkList.second)->iNodeX-Xmax/2)/12, ((iMainWindow::LinkList.second)->iNodeY-Ymax/2)/12);
glEnd();
}
}
void SmallGraph::drawBackground(QPainter *painter)
{
painter->setPen(Qt::NoPen);
painter->setBrush(gradient);
painter->drawRect(rect());
}
void SmallGraph::createGradient()
{
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
gradient.setCenter(0.45, 0.50);
gradient.setFocalPoint(0.40, 0.45);
gradient.setColorAt(0.0, QColor(105, 146, 182));
gradient.setColorAt(0.4, QColor(81, 113, 150));
gradient.setColorAt(0.8, QColor(16, 56, 121));
}
void SmallGraph::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
drawBackground(&painter);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat x = 3.0 * (GLfloat)width()/ height();
gluOrtho2D(-x, +x, -3.0, +3.0);
glMatrixMode(GL_MODELVIEW);
//glScalef(scaling, scaling,1);
DrawLink();
//DrawVertex();
}