I'm working on a little program and I have a bunch of panels in it. I want it so that when I focus into a panel, it draws a thin inline around it to show that it is focused. I got it working with all my panels except my tree view.
Here's an example that works with a QWidget:
void Test::paintEvent(QPaintEvent *event)
{
    if(hasFocus())
    {
        QPainter painter(this);
        QPen pen(Qt::blue);
        pen.setWidth(1);
        painter.setPen(pen);
        painter.drawRect(geometry());
    }
    QWidget::paintEvent(event);
}
When I use the QPainter on the QTreeWidget I get these debug messages in the console:
QWidget::paintEngine: Should no longer be calledQPainter::begin: Paint device returned engine == 0, type: 1QPainter::setPen: Painter not activeQPainter::drawRects: Painter not active
So my problem is that I can't use QPainter with the QTreeWidget so I am unable to draw my outline. Is there an alternative method I can use?
                        
You don't need
paintEventat all. Use just stylesheet (setStyleSheet()method):Result: