[Qt-interest] QStyledItemDelegate

Lars Amsel Lars.Amsel at signalion.com
Wed Jun 17 16:43:02 CEST 2009


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);
}

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.






More information about the Qt-interest-old mailing list