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?
paintEvent
in aQTreeWidget
? You can callQTreeWidget::paintEvent(event)
to perform the painting of the superclass – msrd0QPainter
therefore? AQTreeWidget
should be a subclass ofQWidget
... and btw you should addQWidget::paintEvent(event)
outside of theif
– msrd0QTreeWidget
to it, that should work, but I don't know if that's the best option – msrd0