PDA

View Full Version : Setting border for QGLWidget derived object



fisyher84
1st March 2011, 03:46
Hi to all Qt forum members. I'm new to this forum. I have been learning Qt 4 and programming a GUI application for my project for about a few months now.

Now I have this QGLWidget derived object which I want to paint its border to different color when it receive or lose focus. I have successfully detect the focus change events by reimplement the focusInEvent and focusOutEvent functions but now I'm stuck at setting the border style.

Apparently setStyleSheet doesn't work for QGLWidget. The following is my code for implementing this feature:


void myGLWidget::focusInEvent( QFocusEvent * event )
{
QGLWidget::focusInEvent(event);

if(event->gotFocus())
{
//Set a highlight border
this->setStyleSheet("border: 1px solid white");
}


}

void myGLWidget::focusOutEvent( QFocusEvent * event )
{
QGLWidget::focusOutEvent(event);

if(event->lostFocus())
{
//Set the non focus border
this->setStyleSheet("");
}
}

The border of myGLWidget doesn't change whether I select it or not.

I did set the setFocusPolicy(Qt::StrongFocus) function and also implemented some interactive controls on myGLWidget so I am pretty sure it is selectable.

I tried to look for answers elsewhere but to no avail. Can anyone here help me?

fisyher84
4th March 2011, 05:36
I manage to solve the problem by using OpenGL to draw the viewport borders using Ortho projection instead of Widget style. Still it seems more correct to draw using Widget style. Is there a way to draw the border of OGLWidget-derived widget using Widget style?