[SOLVED] Qt stylesheets: border on a QGLWidget
-
Hi,
I would like to add a border to a QGLWidget derived class when it has the focus. I am using the following code:
@
void myGLWidget::focusInEvent(QFocusEvent* _event)
{
QGLWidget::focusInEvent(event);
setStyleSheet("border: solid 5px red");
}void myGLWidget::focusOutEvent(QFocusEvent* _event)
{
QGLWidget::focusOutEvent(event);
setStyleSheet("border: none;");
}
@As a result, there is no border drawn when the widget takes focus (I added console outputs inside the methods to check if I pass through them). Does anybody know what I am doing wrong?
-
Well, thanks for the answer. I solved the problem using another way. I used a QPainter to draw the border inside glDraw():
@
myGLWidget::myGLWidget()
{
// prevent the widget from being cleared when beginning the QPainter
setAutoFillBackground(false);setAutoBufferSwap(false);
}
void myGLWidget::glDraw()
{
QGLWidget::glDraw();if(hasFocus()) { QPainter painter(this); QPen pen(Qt::yellow, 4); painter.setPen(pen); painter.drawRect(0, 0, width(), height()); } swapBuffers();
}
@