try calling update of tree view on scroll of the view
try calling update of tree view on scroll of the view
I suppose QTreeView::drawRow() or a custom delegate would be better place to draw such things.
J-P Nurmi
Thank you for your suggestions. Unfortunately neither calling update (nor repaint) from any scrolling events helps. It's really odd, because it should, theoretically. Drawing the picture inside drawRow doesn't help either. It still doesn't update it when scrolling. I'll look into creating a custom delegate... I was hoping it'd be something simple, heh. I'm translating an application from Delphi, where those kinds of things are pretty straightforward. But then, I can't complain, because I like Qt infinitely better on most other fronts.
The background picture works really nicely with styles and that would be my preferred solution, but I have to save the picture into a temporary file to load it via a style (background-image: url(xxx)). Is there a way to use this method without saving the file to disk? I tried creating a custom resource, but it only works with rcc files, and I don't want to have to run an external resource compiler to create an rcc file from the picture, since I'll need to save the picture to disk to do that anyway. Any further suggestions before I spend the next week trying to figure out how to create a custom delegate? (Which might or might not work?) Thank you for your time!
Wait a minute, I think I misunderstood the problem. You want to paint a single background image for the tree view, right? Then forget about drawRow() and custom delegate. How do you calculate imageLeftMargin and imageTopMargin?
Last edited by jpn; 24th December 2008 at 14:29. Reason: updated contents
J-P Nurmi
Yes, I want to draw a single background image for the entire tree. The image itself, the left and the right margins are set by the user in the tree properties dialog. So all I need to do is just draw the image at the given coordinates. And I want it to stay there in a fixed position, like it would when applying "background-attachment: fixed". I'm glad to hear you misunderstood the question, that gives me some hope that there's a simple solution.
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:
or with style sheets:Qt Code:
viewport()->setPalette(pal);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:Qt Code:
viewport()->setStyleSheet("background: transparent");To copy to clipboard, switch view to plain text mode
Qt Code:
{ painter.fillRect(event->rect(), palette().base()); // <--- painter.drawImage(imageLeftMargin, imageTopMargin, image); painter.end(); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
Wonderful, it's working just like I wanted it to! Thank you for your help!
Bookmarks