MyItemDelegate
::MyItemDelegate(QObject *object
){
m_label->setTextFormat(Qt::RichText);
}
MyItemDelegate::~MultistringsItemDelegate()
{
delete m_label;
m_label = 0;
}
{
Q_UNUSED(option);
Q_UNUSED(index);
}
{
QLineEdit *lineEdit
= qobject_cast<QLineEdit
*>
(editor
);
if (!lineEdit)
return;
model->setData(index, lineEdit->text());
model
->setData
(index,
QString("<span style=\" color:#0ff000;\">%1</span>").
arg(lineEdit
->text
()), Qt
::DisplayRole);
}
{
m_label->setText(text);
m_label->setPalette(pal);
m_label->resize(option.rect.size());
painter->drawPixmap(option.rect, p);
}
MyItemDelegate::MyItemDelegate(QObject *object)
: QItemDelegate(object)
{
m_label = new QLabel();
m_label->setTextFormat(Qt::RichText);
}
MyItemDelegate::~MultistringsItemDelegate()
{
delete m_label;
m_label = 0;
}
QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return new QLineEdit(parent);
}
void MyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
if (!lineEdit)
return;
model->setData(index, lineEdit->text());
model->setData(index, QString("<span style=\" color:#0ff000;\">%1</span>").arg(lineEdit->text()), Qt::DisplayRole);
}
void MyItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
m_label->setText(text);
QPalette pal(m_label->palette());
pal.setColor(QPalette::Active, QPalette::Window, option.state & QStyle::State_Selected ? pal.color(QPalette::Highlight) : pal.color(QPalette::Base));
m_label->setPalette(pal);
m_label->resize(option.rect.size());
QPixmap p = QPixmap::grabWidget(m_label);
painter->drawPixmap(option.rect, p);
}
To copy to clipboard, switch view to plain text mode
Bookmarks