Results 1 to 6 of 6

Thread: Can't paint in reimplemented QHeaderView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't paint in reimplemented QHeaderView

    Hi!
    I'm having a subclass of QTableView and want to draw icons, the size of which I can freely adjust, in the Horizontal Header and also for the header to support stylesheets.

    From googling around for a while I've been lead to understand that it is not possible without reimplementing the QHeaderView since this class does not support delegates.

    My plan was/is to inherit QHeaderView into a new class (IconHeaderView) and Override the paintSection method in which I would first call QHeaderView::paintSection for it to paint exactly as it does now (with no visible text data in the "header-buttons") and after that, paint my icon on top of the button.
    But I cant get it to work. Nothing visible seems to get drawn on top of the buttons (which render just fine, with or without stylesheets set) using this code:

    Qt Code:
    1. void IconHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
    2. {
    3.  
    4. QHeaderView::paintSection(painter, rect, logicalIndex);
    5.  
    6.  
    7. QPixmap myPixMap(":images/icons/header/ERSicoBUSS.png");
    8. QRect drawingRect;
    9. drawingRect.setHeight(22);
    10. drawingRect.setWidth(60);
    11. drawingRect.moveCenter(rect.center());
    12.  
    13. painter->drawPixmap(drawingRect, myPixMap);
    14.  
    15. qDebug() << "done drawing pixmap";
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    Can anyone tell me what is wrong? I'm guessing there is something funny about the painter used since the exact same code works like a charm in the delegate used for the rest of the table-view.
    Of course I am also open to different approaches as long as it satisfies my requirements: freely resizeble icons and stylesheet support.

    Thanks a bunch!
    /Tottish

    EDIT: Hmm, it seems to work fine if I create a new QPainter on the viewport as so: QPainter myPainter(viewport()). Kind of solves my problem but could someone tell me why is this?
    Last edited by Tottish; 26th February 2011 at 19:11.

Similar Threads

  1. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 20:42
  2. Replies: 2
    Last Post: 4th December 2009, 06:15
  3. QGraphicsItem reimplemented mouse events
    By aarelovich in forum Qt Programming
    Replies: 12
    Last Post: 24th July 2009, 12:56
  4. QHeaderView
    By gyre in forum Qt Tools
    Replies: 1
    Last Post: 25th September 2007, 16:35
  5. QHeaderView as a banner
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 19:28

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.