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:
{
if(event->gotFocus())
{
//Set a highlight border
this->setStyleSheet("border: 1px solid white");
}
}
{
if(event->lostFocus())
{
//Set the non focus border
this->setStyleSheet("");
}
}
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("");
}
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks