The problem is that item views (or delegates) fill the background with QPalette::Base. You can set the view background as transparent with good old palette:
pal.
setColor(QPalette::Base, Qt
::transparent);
viewport()->setPalette(pal);
QPalette pal = viewport()->palette();
pal.setColor(QPalette::Base, Qt::transparent);
viewport()->setPalette(pal);
To copy to clipboard, switch view to plain text mode
or with style sheets:
viewport()->setStyleSheet("background: transparent");
viewport()->setStyleSheet("background: transparent");
To copy to clipboard, switch view to plain text mode
Once you've done that, you can paint the image like you want before calling the base class implementation of paintEvent(). If you want to re-enable the base background you can do it for example like this:
{
painter.fillRect(event->rect(), palette().base()); // <---
painter.drawImage(imageLeftMargin, imageTopMargin, image);
painter.end();
}
void TreeView::paintEvent(QPaintEvent *event)
{
QPainter painter(viewport());
painter.fillRect(event->rect(), palette().base()); // <---
painter.drawImage(imageLeftMargin, imageTopMargin, image);
painter.end();
QTreeView::paintEvent(event);
}
To copy to clipboard, switch view to plain text mode
Bookmarks