[Qt-interest] QStyledItemDelegate

Kaleb Pederson kaleb.pederson at gmail.com
Wed Jun 17 16:53:20 CEST 2009


On Wed, Jun 17, 2009 at 7:43 AM, Lars Amsel<Lars.Amsel at signalion.com>
wrote:> Hi,
>
> I try to customized the item delegate of a table. I want to change the background color of a cell depending on its content. The following works perfect
>
> class MyDelegate : public QStyledItemDelegate {
> protected:
>  virtual void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index ) const;
> };
>
> void MyDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index ) const {
>  QStyledItemDelegate::initStyleOption(option, index);
>  option->palette.setColor(QPalette::Text, Qt::red);
> }

But, why didn't you just change the model's data call so that data()
returns red for Qt::BackgroundRole?

--Kaleb


> Now, every cell displays its text as red. When I change the setColor to
>
> option->palette.setColor(QPalette::Window, Qt::red);
> or
> option->palette.setColor(QPalette::Background, Qt::red);
>
> Nothing happens. I guess the painter thinks the cell is transparent. But how to change that behavior?
>
> Thanks
>
> Lars
>
> ---------------------------------------------------------------------------------------
> Lars Amsel
> Software & Protocols
>
> Signalion GmbH        Tel:   +49 351 2069 31-427
> Am Waldschlösschen 2  Fax:   +49 351 2069 31-11
> 01099 Dresden         Email: lars.amsel at signalion.com
> Germany               Web:   www.signalion.com
> ---------------------------------------------------------------------------------------
>
>
> Signalion GmbH; Geschäftsführer (Managing Directors): Dr. Tim Hentschel, Dr. Thorsten Dräger; Sitz (Registered Office): Dresden; HRB (Commercial Register No.): 22081; Registergericht (Registration Court): Dresden
> This email and any attachments are intended only for the person to which this email is addressed and may contain confidential and/or privileged information.  If you received this email in error, please do not disclose the contents to anyone, but notify the sender by return email and delete this email (and any attachments) from your system.
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>




More information about the Qt-interest-old mailing list