Results 1 to 8 of 8

Thread: Problems with drawing image in paintEvent of QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Problems with drawing image in paintEvent of QTreeView

    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:
    Qt Code:
    1. QPalette pal = viewport()->palette();
    2. pal.setColor(QPalette::Base, Qt::transparent);
    3. viewport()->setPalette(pal);
    To copy to clipboard, switch view to plain text mode 
    or with style sheets:
    Qt Code:
    1. 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:
    Qt Code:
    1. void TreeView::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(viewport());
    4. painter.fillRect(event->rect(), palette().base()); // <---
    5. painter.drawImage(imageLeftMargin, imageTopMargin, image);
    6. painter.end();
    7. QTreeView::paintEvent(event);
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:


  3. #2
    Tito Serenti Guest

    Default Re: Problems with drawing image in paintEvent of QTreeView

    Wonderful, it's working just like I wanted it to! Thank you for your help!

Similar Threads

  1. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  2. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.