I have strange problem I have item delegate inherit from QStyledItemDelegate
the background color is gradient color that looks like this:
void ItemDelegate::paintActiveOverlay( QPainter* painter,
qreal x,
qreal y,
qreal w,
qreal h ) const
{
QPalette palette;
QColor highlightColor = palette.color(QPalette::Highlight);
QColor backgroundColor = palette.color(QPalette::Base);
const float animation = 0.25;
const int gradientRange = 16;
QColor color2 = QColor::fromHsv(
highlightColor.hue(),
(int) (backgroundColor.saturation() * (1.0f - animation) +
highlightColor.saturation() * animation),
(int) (backgroundColor.value() * (1.0f - animation) +
highlightColor.value() * animation) );
QColor color1 = QColor::fromHsv(
color2.hue(),
qMax(color2.saturation() - gradientRange, 0),
qMin(color2.value() + gradientRange, 255) );
QRect rect( (int)x, (int)y, (int)w, (int)h);
painter->save();
painter->setPen(Qt::NoPen);
QLinearGradient linearGradient(0, 0, 0, rect.height());
linearGradient.setColorAt(0.0, color1);
linearGradient.setColorAt(1.0, color2);
painter->setBrush(linearGradient);
painter->drawRect(rect);
painter->restore();
}
It s called from the paint method also in the ItemDelegate
constructor I have set QLabel
like this:
QRect rect(40, 30, 401, 31);
Qt::TextInteractionFlags flags =
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByMouse |
Qt::TextBrowserInteraction |
Qt::TextSelectableByKeyboard |
Qt::TextSelectableByMouse;
Qt::TextFormat txtFormat = Qt::PlainText;
pTextEdit_title = new QLabel();
pTextEdit_title->setTextFormat(txtFormat);
pTextEdit_title->setTextInteractionFlags(flags);
pTextEdit_title->setGeometry(rect);
以及<代码>的油漆方法 项目Delegate i set the QLabel
to make such as:
pTextEdit_title->setText(Title);
QRect TextEditRect(option.rect.x()+THUMB_WIDTH+THUMB_WIDTH+PADDING, option.rect.y() ,
pTextEdit_title->width(), pTextEdit_title->height());
QPixmap pixmap(pTextEdit_title->size());
pTextEdit_title->render(&pixmap);
painter->drawPixmap(TextEditRect,pixmap);
it render the QLabel
file , but the problem is that it has gray background and doesnt act as transparent background , my question is how to set the QLabel
background to be transparent?
also why the TextInteractionFlags i set bean ignored i can t do any thing to the text.