[Qt-interest] How to have dynamic pixmap in a QHeaderView item

David Boosalis david.boosalis at gmail.com
Fri Aug 20 06:50:55 CEST 2010


Thanks for the hint Andre.  I think I almost got it.  A little trouble
seeing the custom pixmap I want to display.  Maybe you know why.  Let me
explain the issue


void MyHeaderView::paintSection( QPainter *p,
                    const QRect &r,
                    int logicalIndex) const
{

  QHeaderView::paintSection(p,r,logicalIndex);  // if I comment this out I
see the pixmap where it should be but on a naked background
  if (logicalIndex == 0) {                  // symbol columm
    //   p->drawPixmap(r.x()+3,r.y()+3,filterPixmap);
         style()->drawItemPixmap(p,r,Qt::AlignLeft,filterPixmap);   // this
behaves just like the line above it, not sure which is better to use
  }


The pixmap never shows up if the QHeaderView::paintSection() is called, but
if I do not call it then I get the pixmap and only the pixmap.  I 'd like to
have the pixmap painted in the left hand corner.

Any suggestions on what to try?   Thank you very much for any feed back.

-David



On Thu, Aug 19, 2010 at 1:51 PM, Andre Somers <andre at familiesomers.nl>wrote:

>  Op 19-8-2010 20:40, David Boosalis schreef:
>
> I want to be able to display a pixmap  in a item of a QTreeView's
> horizontal header. I have created my own Horizontal Header Class, and have
> tried to add my own Delegate to column 0 (the column where I want the pixmap
> to appear).  The trouble is I never see the paint() method for this
> Delegate.
>
> At first I was setting the labels of the header with the model's method
> setHorizontalHeaderLabels(QStringList columnNames).  I then went to the
> trouble of creating a QStandardItem for each column and adding it to the
> header with setHorizontalHeaderItem(col, headerItem).
>
> After both methods I would create my delegate and add it to the header
> with:
>
> MyHeaderDelegate *symbolDelegate = new MyHeaderDelegate(this);
> horHeader->setItemDelegateForColumn(0,myHeaderDelegate);
>
> I never see the debug message I have in the paint() method for
> MyHeaderDelegate.
>
> This is the approach I have used for things such as QTreeView and
> QTableView, but QHeaderView, even though it  inherits from the same base
> class  seems to be the bastard child.  Any ideas on how to be able to paint
> pixmaps for a item in a horizontal header ? I want to be able to control if
> the pixmap gets painted.  Is using a custom delegate the right way to go ?
>
> QHeaderView does not use the delegates, you'll have to draw them yourself
> directly. Sorry. From the documentation:
>
> *Note:* Each header renders the data for each section itself, and does not
> rely on a delegate. As a result, calling a header'ssetItemDelegate<http://qabstractitemview.html#setItemDelegate>()
> function will have no effect.
>
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100819/70955f54/attachment.html 


More information about the Qt-interest-old mailing list